Skip to content

Commit

Permalink
feat: Add 4 methods (#158)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
worldofd2 committed Jan 28, 2024
1 parent 502136e commit fe1b709
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ElunaLuaEngine_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,11 @@ class Eluna_PlayerScript : public PlayerScript
{
sEluna->OnBattlegroundDesertion(player, type);
}

void OnCreatureKilledByPet(Player* player, Creature* killed) override
{
sEluna->OnCreatureKilledByPet(player, killed);
}
};

class Eluna_ServerScript : public ServerScript
Expand Down
1 change: 1 addition & 0 deletions src/LuaEngine/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
1 change: 1 addition & 0 deletions src/LuaEngine/LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ class ELUNA_GAME_API Eluna
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
Expand Down
3 changes: 3 additions & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down
8 changes: 8 additions & 0 deletions src/LuaEngine/PlayerHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
58 changes: 58 additions & 0 deletions src/LuaEngine/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit fe1b709

Please sign in to comment.