feat: Add 4 methods (#158)

1:
Player:GetAchievementPoints

2:
Player:GetCompletedQuestsCount
This should have been GetCompletedQuestsCount, not sure how to update that now.

3: You also have an option to include feats of strength or not (not included by default, blizzard like)
Player:GetCompletedAchievementsCount

4: RegisterPlayerEvent
OnCreatureKilledByPet
This commit is contained in:
mfiners
2024-01-28 06:51:30 -06:00
committed by GitHub
parent 502136e5d6
commit fe1b709c18
6 changed files with 76 additions and 0 deletions

View File

@@ -806,6 +806,11 @@ public:
{
sEluna->OnBattlegroundDesertion(player, type);
}
void OnCreatureKilledByPet(Player* player, Creature* killed) override
{
sEluna->OnCreatureKilledByPet(player, killed);
}
};
class Eluna_ServerScript : public ServerScript

View File

@@ -219,6 +219,7 @@ namespace Hooks
PLAYER_EVENT_ON_CAN_GROUP_INVITE = 55, // (event, player, memberName) - Can return false to prevent inviting
PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM = 56, // (event, player, item, count, voteType, roll)
PLAYER_EVENT_ON_BG_DESERTION = 57, // (event, player, type)
PLAYER_EVENT_ON_PET_KILL = 58, // (event, player, killer)
PLAYER_EVENT_COUNT
};

View File

@@ -490,6 +490,7 @@ public:
bool OnCanGroupInvite(Player* player, std::string& memberName);
void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll);
void OnBattlegroundDesertion(Player* player, const BattlegroundDesertionType type);
void OnCreatureKilledByPet(Player* player, Creature* killed);
#ifndef CLASSIC
#ifndef TBC

View File

@@ -472,6 +472,7 @@ ElunaRegister<Player> PlayerMethods[] =
{ "GetGuild", &LuaPlayer::GetGuild },
{ "GetAccountId", &LuaPlayer::GetAccountId },
{ "GetAccountName", &LuaPlayer::GetAccountName },
{ "GetCompletedQuestsCount", &LuaPlayer::GetCompletedQuestsCount },
#if defined (TBC) || defined (WOTLK)
{ "GetArenaPoints", &LuaPlayer::GetArenaPoints },
{ "GetHonorPoints", &LuaPlayer::GetHonorPoints },
@@ -492,6 +493,8 @@ ElunaRegister<Player> PlayerMethods[] =
{ "GetRestBonus", &LuaPlayer::GetRestBonus },
#ifdef WOTLK
{ "GetPhaseMaskForSpawn", &LuaPlayer::GetPhaseMaskForSpawn },
{ "GetAchievementPoints", &LuaPlayer::GetAchievementPoints },
{ "GetCompletedAchievementsCount", &LuaPlayer::GetCompletedAchievementsCount },
#endif
{ "GetReqKillOrCastCurrentCount", &LuaPlayer::GetReqKillOrCastCurrentCount },
{ "GetQuestStatus", &LuaPlayer::GetQuestStatus },

View File

@@ -698,3 +698,11 @@ void Eluna::OnBattlegroundDesertion(Player* player, const BattlegroundDesertionT
Push(type);
CallAllFunctions(PlayerEventBindings, key);
}
void Eluna::OnCreatureKilledByPet(Player* player, Creature* killed)
{
START_HOOK(PLAYER_EVENT_ON_PET_KILL);
Push(player);
Push(killed);
CallAllFunctions(PlayerEventBindings, key);
}

View File

@@ -903,6 +903,51 @@ namespace LuaPlayer
Eluna::Push(L, player->GetPhaseMaskForSpawn());
return 1;
}
/**
* Returns the [Player]s current amount of Achievement Points
*
* @return uint32 achievementPoints
*/
int GetAchievementPoints(lua_State* L, Player* player)
{
uint32 count = 0;
const CompletedAchievementMap& completedAchievements = player->GetAchievementMgr()->GetCompletedAchievements();
for (auto& pair : completedAchievements)
{
AchievementEntry const* achievement = sAchievementStore.LookupEntry(pair.first);
if (achievement)
{
count += achievement->points;
}
}
Eluna::Push(L, count);
return 1;
}
/**
* Returns the [Player]s current amount of Achievements Completed
*
* @return uint32 achievementsCount
*/
int GetCompletedAchievementsCount(lua_State* L, Player* player)
{
uint32 count = 0;
bool countFeatsOfStrength = Eluna::CHECKVAL<bool>(L, 2, false);
const CompletedAchievementMap& completedAchievements = player->GetAchievementMgr()->GetCompletedAchievements();
for (auto& pair : completedAchievements)
{
AchievementEntry const* achievement = sAchievementStore.LookupEntry(pair.first);
if (achievement && (achievement->categoryId != 81 || countFeatsOfStrength))
{
count++;
}
}
Eluna::Push(L, count);
return 1;
}
#endif
#if defined(TBC) || defined (WOTLK)
@@ -1731,6 +1776,19 @@ namespace LuaPlayer
return 1;
}
/**
* Returns the [Player]s completed quest count
*
* @return int32 questcount
*/
int GetCompletedQuestsCount(lua_State* L, Player* player)
{
uint32 count = player->GetRewardedQuestCount();
Eluna::Push(L, count);
return 1;
}
/**
* Returns the [Player]s [Corpse] object
*