diff --git a/.github/README.md b/.github/README.md new file mode 100644 index 0000000..4c29a00 --- /dev/null +++ b/.github/README.md @@ -0,0 +1,5 @@ +# Guild Funds +[![core-build](https://github.com/tkn963/mod-guildfunds/workflows/core-build/badge.svg?branch=master&event=push)](https://github.com/tkn963/mod-guildfunds/actions?query=workflow%3Acore-build+branch%3Amaster+event%3Apush) + +# Features +This module will deposit a certain percentage of money obtained from quests and money looted into the guild bank. diff --git a/.github/workflows/core-build.yml b/.github/workflows/core-build.yml new file mode 100644 index 0000000..921c9eb --- /dev/null +++ b/.github/workflows/core-build.yml @@ -0,0 +1,12 @@ +name: core-build +on: + push: + branches: + - 'master' + pull_request: + +jobs: + build: + uses: azerothcore/reusable-workflows/.github/workflows/core_build_modules.yml@main + with: + module_repo: ${{ github.event.repository.name }} diff --git a/README.md b/README.md index c073429..9086fd2 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# mod-guildfunds \ No newline at end of file +# Features +This module will deposit a certain percentage of money obtained from quests and money looted into the guild bank. 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/conf/mod_guildfunds.conf.dist b/conf/mod_guildfunds.conf.dist new file mode 100644 index 0000000..b310f40 --- /dev/null +++ b/conf/mod_guildfunds.conf.dist @@ -0,0 +1,13 @@ +[worldserver] + +## +# The amount, in percentage, of money looted to add to the guild bank +# Set to 0 to disable +GuildFunds.Looted = 10 +## + +## +# The amount, in percentage, of money gained from quests to add to the guild bank +# Set to 0 to disable +GuildFunds.Quests = 3 +## diff --git a/include.sh b/include.sh new file mode 100644 index 0000000..1c4cfbd --- /dev/null +++ b/include.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +MOD_GUILDFUNDS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )" + +source $MOD_GUILDFUNDS_ROOT"/conf/conf.sh.dist" + +if [ -f $MOD_GUILDFUNDS_ROOT"/conf/conf.sh" ]; then + source $MOD_GUILDFUNDS_ROOT"/conf/conf.sh" +fi diff --git a/src/loader.cpp b/src/loader.cpp new file mode 100644 index 0000000..2682ffe --- /dev/null +++ b/src/loader.cpp @@ -0,0 +1,6 @@ +void AddGuildFundsScripts(); + +void Addmod_guildfundsScripts() +{ + AddGuildFundsScripts(); +} diff --git a/src/mod_guildfunds.cpp b/src/mod_guildfunds.cpp new file mode 100644 index 0000000..14664c4 --- /dev/null +++ b/src/mod_guildfunds.cpp @@ -0,0 +1,104 @@ +#include "Chat.h" +#include "Config.h" +#include "Guild.h" +#include "Player.h" +#include "ScriptMgr.h" + +uint32 lootFunds; +uint32 questFunds; + +class GuildFundsConfig : WorldScript +{ +public: + GuildFundsConfig() : WorldScript("GuildFundsConfig") {} + + void OnAfterConfigLoad(bool /*reload*/) override + { + lootFunds = sConfigMgr->GetOption("GuildFunds.Looted", 10); + questFunds = sConfigMgr->GetOption("GuildFunds.Quests", 3); + } +}; + +class GuildFundsLoot : LootScript +{ +public: + GuildFundsLoot() : LootScript("GuildFundsLoot") {} + + void OnLootMoney(Player* player, uint32 gold) override + { + if (Guild* guild = player->GetGuild()) + { + uint32 money = ((gold / 100) * questFunds); + + if (money < 0 || lootFunds < 1) + return; + + guild->HandleMemberDepositMoney(player->GetSession(), money); + PrintGuildFundsInformation(player, money); + } + } + +private: + void PrintGuildFundsInformation(Player* player, uint32 money) + { + uint32 gold = money / GOLD; + uint32 silver = (money % GOLD) / SILVER; + uint32 copper = (money % GOLD) % SILVER; + std::string info; + + if (money < SILVER) + info = Acore::StringFormat("%i copper was deposited to the guild bank.", copper); + else if (money < GOLD) + info = Acore::StringFormat("%i silver, %i copper was deposited to the guild bank.", silver, copper); + else + info = Acore::StringFormat("%i gold, %i silver, %i copper was deposited to the guild bank.", gold, silver, copper); + + ChatHandler(player->GetSession()).SendSysMessage(info); + } +}; + +class GuildFundsQuest : public PlayerScript +{ +public: + GuildFundsQuest() : PlayerScript("GuildFundsQuest") {} + + void OnPlayerCompleteQuest(Player* player, Quest const* quest) override + { + if (Guild* guild = player->GetGuild()) + { + uint32 playerLevel = player->getLevel(); + uint32 money = ((quest->GetRewOrReqMoney(playerLevel) / 100) * questFunds); + + if (money < 0 || questFunds < 1) + return; + + guild->HandleMemberDepositMoney(player->GetSession(), money); + PrintGuildFundsInformation(player, money); + } + } + +private: + void PrintGuildFundsInformation(Player* player, uint32 money) + { + uint32 gold = money / GOLD; + uint32 silver = (money % GOLD) / SILVER; + uint32 copper = (money % GOLD) % SILVER; + std::string info; + + if (money < SILVER) + info = Acore::StringFormat("%i copper was deposited to the guild bank.", copper); + else if (money < GOLD) + info = Acore::StringFormat("%i silver, %i copper was deposited to the guild bank.", silver, copper); + else + info = Acore::StringFormat("%i gold, %i silver, %i copper was deposited to the guild bank.", gold, silver, copper); + + ChatHandler(player->GetSession()).SendSysMessage(info); + } +}; + +void AddGuildFundsScripts() +{ + new GuildFundsConfig(); + new GuildFundsLoot(); + new GuildFundsQuest(); +}