Merge pull request #1 from Sdyessdev/Sdyessdev-patch-1

Modernize and cleanup code.
This commit is contained in:
Barbz
2018-03-10 17:39:16 +01:00
committed by GitHub

View File

@@ -73,6 +73,15 @@ reward range of the group and an option to only reward the player that got the k
#include "Config.h" #include "Config.h"
#include "Group.h" #include "Group.h"
enum KillType
{
KILLTYPE_LOOT,
KILLTYPE_PVP,
KILLTYPE_DUNGEONBOSS,
KILLTYPE_WORLDBOSS,
KILLTYPE_MOB
};
class MoneyForKills : public PlayerScript class MoneyForKills : public PlayerScript
{ {
public: public:
@@ -90,7 +99,7 @@ public:
} }
// Player Kill Reward // Player Kill Reward
void OnPVPKill(Player* player, Player* victim) void OnPVPKill(Player* killer, Player* victim)
{ {
// If enabled... // If enabled...
if (sConfigMgr->GetBoolDefault("MFK.Enable", true)) if (sConfigMgr->GetBoolDefault("MFK.Enable", true))
@@ -101,13 +110,14 @@ public:
if (PVPMultiplier > 0) if (PVPMultiplier > 0)
{ {
// No reward for killing yourself // No reward for killing yourself
if (player->GetGUID() == victim->GetGUID()) if (killer->GetGUID() == victim->GetGUID())
{ {
// Inform the world // Inform the world
std::ostringstream ss; std::string message = "|cff676767[ |cffFFFF00World |cff676767]|r:|cff4CFF00 ";
ss << "|cff676767[ |cffFFFF00World |cff676767]|r:|cff4CFF00 " << player->GetName() << " met an untimely demise!"; message.append(killer->GetName());
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str()); message.append(" met an untimely demise!");
sWorld->SendServerMessage(SERVER_MSG_STRING, message.c_str());
return; return;
} }
@@ -117,27 +127,22 @@ public:
const int VictimLoot = (victim->GetMoney() * PVPCorpseLootPercent) / 100; const int VictimLoot = (victim->GetMoney() * PVPCorpseLootPercent) / 100;
const int BountyAmount = ((VictimLevel * PVPMultiplier) / 3); const int BountyAmount = ((VictimLevel * PVPMultiplier) / 3);
// Pay the player the additional PVP bounty
killer->ModifyMoney(BountyAmount);
// Rifle the victim's corpse for loot // Rifle the victim's corpse for loot
if (victim->GetMoney() >= 10000) if (victim->GetMoney() >= 10000)
{ {
// Player loots 5% of the victim's gold // Player loots a percentage of the victim's gold
player->ModifyMoney(VictimLoot); killer->ModifyMoney(VictimLoot);
victim->ModifyMoney(-VictimLoot); victim->ModifyMoney(-VictimLoot);
// Inform the player of the corpse loot // Inform the player of the corpse loot
Notify(player, victim, NULL, "Loot", 0, VictimLoot); Notify(killer, victim, nullptr, KILLTYPE_LOOT, VictimLoot);
// Pay the player the additional PVP bounty
player->ModifyMoney(BountyAmount);
}
else
{
// Pay the player the additional PVP bounty
player->ModifyMoney(BountyAmount);
} }
// Inform the player of the bounty amount // Inform the player of the bounty amount
Notify(player, victim, NULL, "PVP", BountyAmount, VictimLoot); Notify(killer, victim, nullptr, KILLTYPE_PVP, BountyAmount);
return; return;
} }
@@ -177,12 +182,12 @@ public:
if (killed->IsDungeonBoss()) if (killed->IsDungeonBoss())
{ {
// Pay the bounty amount // Pay the bounty amount
CreatureBounty(player, killed, "DungeonBoss", BountyAmount); CreatureBounty(player, killed, KILLTYPE_DUNGEONBOSS, BountyAmount);
} }
else else
{ {
// Pay the bounty amount // Pay the bounty amount
CreatureBounty(player, killed, "WorldBoss", BountyAmount); CreatureBounty(player, killed, KILLTYPE_WORLDBOSS, BountyAmount);
} }
} }
} }
@@ -197,14 +202,14 @@ public:
const int BountyAmount = ((CreatureLevel * KillMultiplier) / 3); const int BountyAmount = ((CreatureLevel * KillMultiplier) / 3);
// Pay the bounty amount // Pay the bounty amount
CreatureBounty(player, killed, "MOB", BountyAmount); CreatureBounty(player, killed, KILLTYPE_MOB, BountyAmount);
} }
} }
} }
} }
// Pay Creature Bounty // Pay Creature Bounty
void CreatureBounty(Player* player, Creature* killed, string KillType, int bounty) void CreatureBounty(Player* player, Creature* killed, KillType kType, int bounty)
{ {
Group* group = player->GetGroup(); Group* group = player->GetGroup();
Group::MemberSlotList const &members = group->GetMemberSlots(); Group::MemberSlotList const &members = group->GetMemberSlots();
@@ -218,7 +223,7 @@ public:
player->ModifyMoney(bounty); player->ModifyMoney(bounty);
// Inform the player of the bounty amount // Inform the player of the bounty amount
Notify(player, NULL, killed, KillType, bounty, 0); Notify(player, nullptr, killed, kType, bounty);
} }
else else
{ {
@@ -238,7 +243,7 @@ public:
playerInGroup->ModifyMoney(bounty); playerInGroup->ModifyMoney(bounty);
// Inform the player of the bounty amount // Inform the player of the bounty amount
Notify(playerInGroup, NULL, killed, KillType, bounty, 0); Notify(playerInGroup, nullptr, killed, kType, bounty);
} }
else else
{ {
@@ -249,7 +254,7 @@ public:
playerInGroup->ModifyMoney(bounty); playerInGroup->ModifyMoney(bounty);
// Inform the player of the bounty amount // Inform the player of the bounty amount
Notify(playerInGroup, NULL, killed, KillType, bounty, 0); Notify(playerInGroup, nullptr, killed, kType, bounty);
} }
} }
} }
@@ -257,137 +262,69 @@ public:
} }
} }
// Payment/Kill Notification void Notify(Player * killer, Player * victim, Creature * killed, KillType kType, int reward)
void Notify(Player* player, Player* victim, Creature* killed, string KillType, int bounty, int loot)
{ {
std::ostringstream ss; int rewardBreakdown[3];
std::ostringstream sv; rewardBreakdown[0] = reward / 10000;
int result[3]; reward = reward - rewardBreakdown[0] * 10000;
rewardBreakdown[1] = reward / 100;
rewardBreakdown[2] = reward - (rewardBreakdown[1] * 100);
// Determine type of kill std::string rewardMsg = "";
if (KillType == "Loot") std::string victimMsg = "";
std::string rewardVal = BuildRewardString(&rewardBreakdown[0]);
switch (kType)
{ {
const int copper = loot % 100; case KILLTYPE_LOOT:
loot = (loot - copper) / 100; rewardMsg.append("You loot").append(rewardVal).append(" from the corpse.");
const int silver = loot % 100; victimMsg.append(killer->GetName()).append(" rifles through your corpse and takes").append(rewardVal);
const int gold = (loot - silver) / 100; victimMsg.append(".");
result[0] = copper; ChatHandler(victim->GetSession()).SendSysMessage(victimMsg.c_str());
result[1] = silver; break;
result[2] = gold; case KILLTYPE_PVP:
} rewardMsg.append("|cff676767[ |cffFFFF00World |cff676767]|r:|cff4CFF00 ").append(killer->GetName()).append(" |cffFF0000has slain ");
else rewardMsg.append(victim->GetName()).append(" earning a bounty of").append(rewardVal).append(".");
{ sWorld->SendServerMessage(SERVER_MSG_STRING, rewardMsg.c_str());
const int copper = bounty % 100; break;
bounty = (bounty - copper) / 100; case KILLTYPE_DUNGEONBOSS:
const int silver = bounty % 100; rewardMsg.append("|cffFF8000Your group has defeated |cffFF0000").append(killed->GetName()).append("|cffFF8000.");
const int gold = (bounty - silver) / 100; ChatHandler(killer->GetSession()).SendSysMessage(rewardMsg.c_str());
result[0] = copper; rewardMsg.clear();
result[1] = silver; break;
result[2] = gold; case KILLTYPE_WORLDBOSS:
rewardMsg.append("|cffFF0000[ |cffFFFF00World |cffFF0000]|r:|cff4CFF00 ").append(killer->GetName());
rewardMsg.append("'s|r group triumphed victoriously over |CFF18BE00[").append(killed->GetName()).append("]|r !");
sWorld->SendServerMessage(SERVER_MSG_STRING, rewardMsg.c_str());
rewardMsg.clear();
break;
case KILLTYPE_MOB:
break;
} }
// Payment notification if (kType != KILLTYPE_PVP)
if (KillType == "Loot")
{ {
ss << "You loot ";
sv << player->GetName() << " rifles through your corpse and takes ";
}
else if (KillType == "PVP")
{
ss << "|cff676767[ |cffFFFF00World |cff676767]|r:|cff4CFF00 " << player->GetName() << " |cffFF0000has slain " << victim->GetName() << " earning a bounty of ";
}
else
{
ss << "You receive a bounty of ";
}
// Figure out the money (todo: find a better way to handle the different strings) rewardMsg.append(" You receive a bounty of");
if (result[2] > 0) rewardMsg.append(rewardVal);
{ ChatHandler(killer->GetSession()).SendSysMessage(rewardMsg.c_str());
ss << result[2] << " gold"; rewardMsg.append(" for the kill.");
sv << result[2] << " gold";
} }
if (result[1] > 0) }
{
if (result[2] > 0)
{
ss << " " << result[1] << " silver";
sv << " " << result[1] << " silver";
}
else
{
ss << result[1] << " silver";
sv << result[1] << " silver";
} std::string BuildRewardString(int * reward)
} {
if (result[0] > 0) std::string currSymbol[3] = { " gold", " silver", " copper" };
std::string rewardMsg = "";
for (int i = 0; i < 3; i++)
{ {
if (result[1] > 0) if (reward[i] > 0)
{ {
ss << " " << result[0] << " copper"; rewardMsg.append(" ").append(std::to_string(reward[i]));
sv << " " << result[0] << " copper"; rewardMsg.append(currSymbol[i]);
}
else
{
ss << result[0] << " copper";
sv << result[0] << " copper";
} }
} }
// Type of kill return rewardMsg;
if (KillType == "Loot")
{
ss << " from the corpse.";
sv << ".";
}
else if (KillType == "PVP")
{
ss << ".";
sv << ".";
}
else
{
ss << " for the kill.";
}
// If it's a boss kill..
if (KillType == "WorldBoss")
{
// Inform the world of the kill
std::ostringstream sw;
sw << "|cffFF0000[ |cffFFFF00World |cffFF0000]|r:|cff4CFF00 " << player->GetName() << "'s|r group triumphed victoriously over |CFF18BE00[" << killed->GetName() << "]|r !";
sWorld->SendServerMessage(SERVER_MSG_STRING, sw.str().c_str());
// Inform the player of the bounty
ChatHandler(player->GetSession()).SendSysMessage(ss.str().c_str());
}
else if (KillType == "Loot")
{
// Inform the player of the corpse loot
ChatHandler(player->GetSession()).SendSysMessage(ss.str().c_str());
// Inform the victim of the corpse loot
ChatHandler(victim->GetSession()).SendSysMessage(sv.str().c_str());
}
else if (KillType == "PVP")
{
// Inform the world of the kill
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
}
else
{
if (KillType == "DungeonBoss")
{
// Inform the player of the Dungeon Boss kill
std::ostringstream sb;
sb << "|cffFF8000Your group has defeated |cffFF0000" << killed->GetName() << "|cffFF8000.";
ChatHandler(player->GetSession()).SendSysMessage(sb.str().c_str());
}
// Inform the player of the bounty
ChatHandler(player->GetSession()).SendSysMessage(ss.str().c_str());
}
} }
}; };