Restructure
Restructured the module based on my progression module in anticipation of it being made public.
This commit is contained in:
parent
206b5a3a3a
commit
8d6848ba24
6 changed files with 151 additions and 162 deletions
|
|
@ -1,6 +0,0 @@
|
||||||
void AddGuildFundsScripts();
|
|
||||||
|
|
||||||
void Addmod_guildfundsScripts()
|
|
||||||
{
|
|
||||||
AddGuildFundsScripts();
|
|
||||||
}
|
|
||||||
|
|
@ -1,160 +1,8 @@
|
||||||
#include "Chat.h"
|
#include "mod_guildfunds.h"
|
||||||
#include "Config.h"
|
|
||||||
#include "Guild.h"
|
|
||||||
#include "Player.h"
|
|
||||||
#include "ScriptMgr.h"
|
|
||||||
|
|
||||||
bool gfShowInfo;
|
GuildFunds::GuildFunds() : LootScript("GuildFundsLootScript"), PlayerScript("GuildFundsPlayerScript"), WorldScript("GuildFundsWorldScript") {}
|
||||||
uint32 gfLootMultiplier;
|
|
||||||
uint32 gfQuestMultiplier;
|
|
||||||
|
|
||||||
class GuildFundsConfig : WorldScript
|
void Addmod_guildfundsScripts()
|
||||||
{
|
{
|
||||||
public:
|
new GuildFunds();
|
||||||
GuildFundsConfig() : WorldScript("GuildFundsConfig") {}
|
|
||||||
|
|
||||||
void OnAfterConfigLoad(bool /*reload*/) override
|
|
||||||
{
|
|
||||||
gfShowInfo = sConfigMgr->GetOption<bool>("GuildFunds.ShowInfo", 1);
|
|
||||||
gfLootMultiplier = sConfigMgr->GetOption<uint32>("GuildFunds.Looted", 10);
|
|
||||||
gfQuestMultiplier = sConfigMgr->GetOption<uint32>("GuildFunds.Quests", 3);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class GuildFundsLoot : LootScript
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GuildFundsLoot() : LootScript("GuildFundsLoot") {}
|
|
||||||
|
|
||||||
void OnLootMoney(Player* player, uint32 gold) override
|
|
||||||
{
|
|
||||||
if (Group* group = player->GetGroup())
|
|
||||||
{
|
|
||||||
uint32 membersInRange = 0;
|
|
||||||
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
|
|
||||||
{
|
|
||||||
if (Player* member = groupRef->GetSource())
|
|
||||||
{
|
|
||||||
if (member->IsAtLootRewardDistance(player))
|
|
||||||
membersInRange++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gfLootMultiplier < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint32 money = (gold / membersInRange) * gfLootMultiplier / 100;
|
|
||||||
|
|
||||||
if (money < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
|
|
||||||
{
|
|
||||||
if (Player* member = groupRef->GetSource())
|
|
||||||
{
|
|
||||||
if (member->IsAtLootRewardDistance(player))
|
|
||||||
{
|
|
||||||
if (Guild* guild = member->GetGuild())
|
|
||||||
{
|
|
||||||
guild->HandleMemberDepositMoney(member->GetSession(), money);
|
|
||||||
member->ModifyMoney(money);
|
|
||||||
|
|
||||||
if (gfShowInfo)
|
|
||||||
PrintGuildFundsInformation(member, money);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Guild* guild = player->GetGuild())
|
|
||||||
{
|
|
||||||
uint32 money = gold * gfLootMultiplier / 100;
|
|
||||||
|
|
||||||
if (money < 1 || gfLootMultiplier < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
guild->HandleMemberDepositMoney(player->GetSession(), money);
|
|
||||||
player->ModifyMoney(money);
|
|
||||||
|
|
||||||
if (gfShowInfo)
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
if (gfQuestMultiplier < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint32 playerLevel = player->GetLevel();
|
|
||||||
|
|
||||||
if (quest->GetRewOrReqMoney(playerLevel) < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint32 money = quest->GetRewOrReqMoney(playerLevel) * gfQuestMultiplier / 100;
|
|
||||||
|
|
||||||
if (money < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
guild->HandleMemberDepositMoney(player->GetSession(), money);
|
|
||||||
player->ModifyMoney(money);
|
|
||||||
|
|
||||||
if (gfShowInfo)
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
src/mod_guildfunds.h
Normal file
28
src/mod_guildfunds.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef MOD_GUILDFUNDS
|
||||||
|
#define MOD_GUILDFUNDS
|
||||||
|
|
||||||
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
|
class GuildFunds : public LootScript, PlayerScript, WorldScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GuildFunds();
|
||||||
|
|
||||||
|
// LootScript
|
||||||
|
void OnLootMoney(Player* /*player*/, uint32 /*gold*/) override;
|
||||||
|
|
||||||
|
// PlayerScript
|
||||||
|
void OnPlayerCompleteQuest(Player* /*player*/, Quest const* /*quest*/) override;
|
||||||
|
|
||||||
|
// WorldScript
|
||||||
|
void OnAfterConfigLoad(bool /*reload*/) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool ShowInfo;
|
||||||
|
uint32 LootMultiplier;
|
||||||
|
uint32 QuestMultiplier;
|
||||||
|
|
||||||
|
void SendFundsInformation(Player* /*player*/, uint32 /*money*/);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
10
src/mod_guildfunds_config.cpp
Normal file
10
src/mod_guildfunds_config.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
#include "mod_guildfunds.h"
|
||||||
|
|
||||||
|
void GuildFunds::OnAfterConfigLoad(bool /*reload*/)
|
||||||
|
{
|
||||||
|
ShowInfo = sConfigMgr->GetOption<bool>("GuildFunds.ShowInfo", 1);
|
||||||
|
LootMultiplier = sConfigMgr->GetOption<uint32>("GuildFunds.Looted", 10);
|
||||||
|
QuestMultiplier = sConfigMgr->GetOption<uint32>("GuildFunds.Quests", 3);
|
||||||
|
}
|
||||||
62
src/mod_guildfunds_loot.cpp
Normal file
62
src/mod_guildfunds_loot.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "Guild.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
|
#include "mod_guildfunds.h"
|
||||||
|
|
||||||
|
void GuildFunds::OnLootMoney(Player* player, uint32 gold)
|
||||||
|
{
|
||||||
|
if (Group* group = player->GetGroup())
|
||||||
|
{
|
||||||
|
uint32 membersInRange = 0;
|
||||||
|
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
|
||||||
|
{
|
||||||
|
if (Player* member = groupRef->GetSource())
|
||||||
|
{
|
||||||
|
if (member->IsAtLootRewardDistance(player))
|
||||||
|
membersInRange++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LootMultiplier < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32 money = (gold / membersInRange) * LootMultiplier / 100;
|
||||||
|
|
||||||
|
if (money < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (GroupReference* groupRef = group->GetFirstMember(); groupRef != nullptr; groupRef = groupRef->next())
|
||||||
|
{
|
||||||
|
if (Player* member = groupRef->GetSource())
|
||||||
|
{
|
||||||
|
if (member->IsAtLootRewardDistance(player))
|
||||||
|
{
|
||||||
|
if (Guild* guild = member->GetGuild())
|
||||||
|
{
|
||||||
|
guild->HandleMemberDepositMoney(member->GetSession(), money);
|
||||||
|
member->ModifyMoney(money);
|
||||||
|
|
||||||
|
if (ShowInfo)
|
||||||
|
SendFundsInformation(member, money);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Guild* guild = player->GetGuild())
|
||||||
|
{
|
||||||
|
uint32 money = gold * LootMultiplier / 100;
|
||||||
|
|
||||||
|
if (money < 1 || LootMultiplier < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
guild->HandleMemberDepositMoney(player->GetSession(), money);
|
||||||
|
player->ModifyMoney(money);
|
||||||
|
|
||||||
|
if (ShowInfo)
|
||||||
|
SendFundsInformation(player, money);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/mod_guildfunds_player.cpp
Normal file
47
src/mod_guildfunds_player.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
#include "Chat.h"
|
||||||
|
#include "Guild.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
|
#include "mod_guildfunds.h"
|
||||||
|
|
||||||
|
void GuildFunds::OnPlayerCompleteQuest(Player* player, Quest const* quest)
|
||||||
|
{
|
||||||
|
if (Guild* guild = player->GetGuild())
|
||||||
|
{
|
||||||
|
if (QuestMultiplier < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32 playerLevel = player->GetLevel();
|
||||||
|
|
||||||
|
if (quest->GetRewOrReqMoney(playerLevel) < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32 money = quest->GetRewOrReqMoney(playerLevel) * QuestMultiplier / 100;
|
||||||
|
|
||||||
|
if (money < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
guild->HandleMemberDepositMoney(player->GetSession(), money);
|
||||||
|
player->ModifyMoney(money);
|
||||||
|
|
||||||
|
if (ShowInfo)
|
||||||
|
SendFundsInformation(player, money);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuildFunds::SendFundsInformation(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);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue