diff --git a/README.md b/README.md index 5509b6e..77e59cf 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# mod-junk-to-gold \ No newline at end of file +# Junk to Gold +This module will automatically sell gray items when the player loots them diff --git a/conf/conf.sh.dist b/conf/conf.sh.dist new file mode 100644 index 0000000..f1f641a --- /dev/null +++ b/conf/conf.sh.dist @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/include.sh b/include.sh new file mode 100644 index 0000000..88f9e75 --- /dev/null +++ b/include.sh @@ -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 diff --git a/src/mod_junk_to_gold.cpp b/src/mod_junk_to_gold.cpp new file mode 100644 index 0000000..ed8a8b1 --- /dev/null +++ b/src/mod_junk_to_gold.cpp @@ -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(); +}