Files
mod-ale/PlayerMethods.h
2016-01-24 19:29:42 +02:00

4043 lines
112 KiB
C++

/*
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef PLAYERMETHODS_H
#define PLAYERMETHODS_H
/***
* Inherits all methods from: [Object], [WorldObject], [Unit]
*/
namespace LuaPlayer
{
#if (!defined(TBC) && !defined(CLASSIC))
/**
* Returns 'true' if the [Player] can Titan Grip, 'false' otherwise.
*
* @return bool canTitanGrip
*/
int CanTitanGrip(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->CanTitanGrip());
return 1;
}
/**
* Returns 'true' if the [Player] has a talent by ID in specified talent tree, 'false' otherwise.
*
* @param uint32 talentId : talent ID to check
* @param uint8 spec : specified talent tree
* @return bool hasTalent
*/
int HasTalent(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 talentId = Eluna::CHECKVAL<uint32>(L, 2);
uint8 spec = Eluna::CHECKVAL<uint8>(L, 3);
if (spec < MAX_TALENT_SPECS)
return 1;
Eluna::Push(L, player->HasTalent(talentId, spec));
return 1;
}
/**
* Returns 'true' if the [Player] has completed the specified achievement, 'false' otherwise.
*
* @param uint32 achievementId
* @return bool hasAchieved
*/
int HasAchieved(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 achievementId = Eluna::CHECKVAL<uint32>(L, 2);
#ifndef TRINITY
Eluna::Push(L, player->GetAchievementMgr().HasAchievement(achievementId));
#else
Eluna::Push(L, player->HasAchieved(achievementId));
#endif
return 1;
}
#endif
/**
* Returns 'true' if the [Player] has an active [Quest] by specific ID, 'false' otherwise.
*
* @param uint32 questId
* @return bool hasQuest
*/
int HasQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 quest = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->IsActiveQuest(quest));
return 1;
}
/**
* Returns 'true' if the [Player] has a skill by specific ID, 'false' otherwise.
*
* @param uint32 skill
* @return bool hasSkill
*/
int HasSkill(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->HasSkill(skill));
return 1;
}
/**
* Returns 'true' if the [Player] has a [Spell] by specific ID, 'false' otherwise.
*
* @param uint32 spellId
* @return bool hasSpell
*/
int HasSpell(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->HasSpell(id));
return 1;
}
/**
* Returns true if [Player] has specified login flag
*
* @param uint32 flag
* @return bool hasLoginFlag
*/
int HasAtLoginFlag(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 flag = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->HasAtLoginFlag((AtLoginFlags)flag));
return 1;
}
/**
* Returns true if [Player] has [Quest] for [GameObject]
*
* @param int32 entry : entry of a [GameObject]
* @return bool hasQuest
*/
int HasQuestForGO(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 entry = Eluna::CHECKVAL<int32>(L, 2);
Eluna::Push(L, player->HasQuestForGO(entry));
return 1;
}
#ifndef CLASSIC
/**
* Returns 'true' if the [Player] has a title by specific ID, 'false' otherwise.
*
* @param uint32 titleId
* @return bool hasTitle
*/
int HasTitle(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (titleInfo)
Eluna::Push(L, player->HasTitle(titleInfo));
return 1;
}
#endif
/**
* Returns 'true' if the [Player] has the given amount of item entry specified, 'false' otherwise.
*
* @param uint32 itemId : entry of the item
* @param uint32 count = 1 : amount of items the player needs should have
* @param bool check_bank = false : determines if the item can be in player bank
* @return bool hasItem
*/
int HasItem(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 itemId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 count = Eluna::CHECKVAL<uint32>(L, 3, 1);
bool check_bank = Eluna::CHECKVAL<bool>(L, 4, false);
Eluna::Push(L, player->HasItemCount(itemId, count, check_bank));
return 1;
}
/**
* Returns 'true' if the [Player] has a quest for the item entry specified, 'false' otherwise.
*
* @param uint32 entry : entry of the item
* @return bool hasQuest
*/
int HasQuestForItem(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->HasQuestForItem(entry));
return 1;
}
/**
* Returns 'true' if the [Player] can use the item or item entry specified, 'false' otherwise.
*
* @proto canUse = (item)
* @proto canUse = (entry)
* @param [Item] item : an instance of an item
* @param uint32 entry : entry of the item
* @return bool canUse
*/
int CanUseItem(Eluna* /*E*/, lua_State* L, Player* player)
{
Item* item = Eluna::CHECKOBJ<Item>(L, 2, false);
if (item)
Eluna::Push(L, player->CanUseItem(item) == EQUIP_ERR_OK);
else
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
if (temp)
Eluna::Push(L, player->CanUseItem(temp) == EQUIP_ERR_OK);
else
Eluna::Push(L, false);
}
return 1;
}
/**
* Returns 'true' if the [Spell] specified by ID is currently on cooldown for the [Player], 'false' otherwise.
*
* @param uint32 spellId
* @return bool hasSpellCooldown
*/
int HasSpellCooldown(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
#ifdef TRINITY
Eluna::Push(L, player->GetSpellHistory()->HasCooldown(spellId));
#else
Eluna::Push(L, player->HasSpellCooldown(spellId));
#endif
return 1;
}
/**
* Returns 'true' if the [Player] can share [Quest] specified by ID, 'false' otherwise.
*
* @param uint32 entryId
* @return bool hasSpellCooldown
*/
int CanShareQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->CanShareQuest(entry));
return 1;
}
/**
* Returns 'true' if the [Player] can currently communicate through chat, 'false' otherwise.
*
* @return bool canSpeak
*/
int CanSpeak(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->CanSpeak());
return 1;
}
/**
* Returns 'true' if the [Player] has permission to uninvite others from the current group, 'false' otherwise.
*
* @return bool canUninviteFromGroup
*/
int CanUninviteFromGroup(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->CanUninviteFromGroup() == ERR_PARTY_RESULT_OK);
return 1;
}
#ifndef CLASSIC
/**
* Returns 'true' if the [Player] can fly, 'false' otherwise.
*
* @return bool canFly
*/
int CanFly(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->CanFly());
return 1;
}
#endif
#ifdef CLASSIC
/**
* Returns [Player] kills
*
* @param bool honorable = true : if victims are honorable
* @return uint32 kills
*/
int GetHonorStoredKills(Eluna* /*E*/, lua_State* L, Player* player)
{
bool honorable = Eluna::CHECKVAL<bool>(L, 2, true);
Eluna::Push(L, player->GetHonorStoredKills(honorable));
return 1;
}
/**
* Returns rank points
*
* @return float rankPoints
*/
int GetRankPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetRankPoints());
return 1;
}
/**
* Returns last week's standing position
*
* @return int32 standingPos
*/
int GetHonorLastWeekStandingPos(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetHonorLastWeekStandingPos());
return 1;
}
#endif
/**
* Returns 'true' if the [Player] is currently in water, 'false' otherwise.
*
* @return bool isInWater
*/
int IsInWater(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->IsInWater());
return 1;
}
/**
* Returns 'true' if the [Player] is currently moving, 'false' otherwise.
*
* @return bool isMoving
*/
int IsMoving(Eluna* /*E*/, lua_State* L, Player* player) // enable for unit when mangos support it
{
Eluna::Push(L, player->isMoving());
return 1;
}
#ifdef CLASSIC
/**
* Updates the [Player]s weekly honor status
*/
int UpdateHonor(Eluna* /*E*/, lua_State* L, Player* player)
{
player->UpdateHonor();
return 0;
}
/**
* Resets the [Player]s weekly honor status
*/
int ResetHonor(Eluna* /*E*/, lua_State* L, Player* player)
{
player->ResetHonor();
return 0;
}
/**
* Clears all of [Player]s weekly honor status
*/
int ClearHonorInfo(Eluna* /*E*/, lua_State* L, Player* player)
{
player->ClearHonorInfo();
return 0;
}
#endif
#ifndef CLASSIC
/**
* Returns 'true' if the [Player] is currently flying, 'false' otherwise.
*
* @return bool isFlying
*/
int IsFlying(Eluna* /*E*/, lua_State* L, Player* player) // enable for unit when mangos support it
{
Eluna::Push(L, player->IsFlying());
return 1;
}
#endif
/**
* Returns 'true' if the [Player] is in a [Group], 'false' otherwise.
*
* @return bool isInGroup
*/
int IsInGroup(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, (player->GetGroup() != NULL));
return 1;
}
/**
* Returns 'true' if the [Player] is in a [Guild], 'false' otherwise.
*
* @return bool isInGuild
*/
int IsInGuild(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, (player->GetGuildId() != 0));
return 1;
}
/**
* Returns 'true' if the [Player] is a Game Master, 'false' otherwise.
*
* Note: This is only true when GM tag is activated! For alternative see [Player:GetGMRank]
*
* @return bool isGM
*/
int IsGM(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->isGameMaster());
#else
Eluna::Push(L, player->IsGameMaster());
#endif
return 1;
}
#ifndef CLASSIC
/**
* Returns 'true' if the [Player] is in an arena team specified by type, 'false' otherwise.
*
* @param uint32 type
* @return bool isInArenaTeam
*/
int IsInArenaTeam(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 type = Eluna::CHECKVAL<uint32>(L, 2);
if (type < MAX_ARENA_SLOT && player->GetArenaTeamId(type))
Eluna::Push(L, true);
else
Eluna::Push(L, false);
return 1;
}
#endif
/**
* Returns 'true' if the [Player] satisfies all requirements to complete the quest entry.
*
* @param uint32 entry
* @return bool canComplete
*/
int CanCompleteQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->CanCompleteQuest(entry));
return 1;
}
/**
* Returns 'true' if the [Player] is a part of the Horde faction, 'false' otherwise.
*
* @return bool isHorde
*/
int IsHorde(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, (player->GetTeam() == HORDE));
return 1;
}
/**
* Returns 'true' if the [Player] is a part of the Alliance faction, 'false' otherwise.
*
* @return bool isAlliance
*/
int IsAlliance(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, (player->GetTeam() == ALLIANCE));
return 1;
}
/**
* Returns 'true' if the [Player] is 'Do Not Disturb' flagged, 'false' otherwise.
*
* @return bool isDND
*/
int IsDND(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->isDND());
return 1;
}
/**
* Returns 'true' if the [Player] is 'Away From Keyboard' flagged, 'false' otherwise.
*
* @return bool isAFK
*/
int IsAFK(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->isAFK());
return 1;
}
/**
* Returns 'true' if the [Player] is currently falling, 'false' otherwise.
*
* @return bool isFalling
*/
int IsFalling(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->IsFalling());
return 1;
}
int IsGroupVisibleFor(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* target = Eluna::CHECKOBJ<Player>(L, 2);
Eluna::Push(L, player->IsGroupVisibleFor(target));
return 1;
}
/**
* Returns 'true' if the [Player] is currently in the same raid as another [Player] by object, 'false' otherwise.
*
* @param [Player] player
* @return bool isInSameRaidWith
*/
int IsInSameRaidWith(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* target = Eluna::CHECKOBJ<Player>(L, 2);
Eluna::Push(L, player->IsInSameRaidWith(target));
return 1;
}
/**
* Returns 'true' if the [Player] is currently in the same [Group] as another [Player] by object, 'false' otherwise.
*
* @param [Player] player
* @return bool isInSameGroupWith
*/
int IsInSameGroupWith(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* target = Eluna::CHECKOBJ<Player>(L, 2);
Eluna::Push(L, player->IsInSameGroupWith(target));
return 1;
}
/**
* Returns 'true' if the [Player] is eligible for Honor or XP gain by [Unit] specified, 'false' otherwise.
*
* @param [Unit] unit
* @return bool isHonorOrXPTarget
*/
int IsHonorOrXPTarget(Eluna* /*E*/, lua_State* L, Player* player)
{
Unit* victim = Eluna::CHECKOBJ<Unit>(L, 2);
Eluna::Push(L, player->isHonorOrXPTarget(victim));
return 1;
}
/**
* Returns 'true' if the [Player] can see anoter [Player] specified by object, 'false' otherwise.
*
* @param [Player] player
* @return bool isVisibleForPlayer
*/
int IsVisibleForPlayer(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* target = Eluna::CHECKOBJ<Player>(L, 2);
Eluna::Push(L, player->IsVisibleGloballyFor(target));
return 1;
}
int IsGMVisible(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->isGMVisible());
return 1;
}
/**
* Returns 'true' if the [Player] has taxi cheat activated, 'false' otherwise.
*
* @return bool isTaxiCheater
*/
int IsTaxiCheater(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifdef MANGOS
Eluna::Push(L, player->IsTaxiCheater());
#else
Eluna::Push(L, player->isTaxiCheater());
#endif
return 1;
}
int IsGMChat(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->isGMChat());
return 1;
}
/**
* Returns 'true' if the [Player] is accepting whispers, 'false' otherwise.
*
* @return bool isAcceptingWhispers
*/
int IsAcceptingWhispers(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->isAcceptWhispers());
return 1;
}
/**
* Returns 'true' if the [Player] is currently rested, 'false' otherwise.
*
* @return bool isRested
*/
int IsRested(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetRestBonus() > 0.0f);
return 1;
}
/**
* Returns 'true' if the [Player] is currently in a [BattleGround] queue, 'false' otherwise.
*
* @return bool inBattlegroundQueue
*/
int InBattlegroundQueue(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->InBattleGroundQueue());
#else
Eluna::Push(L, player->InBattlegroundQueue());
#endif
return 1;
}
#ifndef CLASSIC
/**
* Returns 'true' if the [Player] is currently in an arena, 'false' otherwise.
*
* @return bool inArena
*/
int InArena(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->InArena());
return 1;
}
#endif
/**
* Returns 'true' if the [Player] is currently in a [BattleGround], 'false' otherwise.
*
* @return bool inBattleGround
*/
int InBattleground(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->InBattleGround());
#else
Eluna::Push(L, player->InBattleground());
#endif
return 1;
}
/**
* Returns 'true' if the [Player] can block incomming attacks, 'false' otherwise.
*
* @return bool canBlock
*/
int CanBlock(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->CanBlock());
return 1;
}
/**
* Returns 'true' if the [Player] can parry incomming attacks, 'false' otherwise.
*
* @return bool canParry
*/
int CanParry(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->CanParry());
return 1;
}
/*int HasReceivedQuestReward(Eluna* E, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->IsQuestRewarded(entry));
return 1;
}*/
/*int IsOutdoorPvPActive(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->IsOutdoorPvPActive());
return 1;
}*/
/*int IsImmuneToEnvironmentalDamage(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->IsImmuneToEnvironmentalDamage());
return 1;
}*/
/*int InRandomLfgDungeon(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->inRandomLfgDungeon());
return 1;
}*/
/*int IsUsingLfg(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->isUsingLfg());
return 1;
}*/
/*int IsNeverVisible(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->IsNeverVisible());
return 1;
}*/
/*int CanFlyInZone(Eluna* E, lua_State* L, Player* player)
{
uint32 mapid = Eluna::CHECKVAL<uint32>(L, 2);
uint32 zone = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->IsKnowHowFlyIn(mapid, zone));
return 1;
}*/
/*int HasPendingBind(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->PendingHasPendingBind());
return 1;
}*/
/*int IsARecruiter(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->IsARecruiter() || (player->GetSession()->GetRecruiterId() != 0));
return 1;
}*/
#if (!defined(TBC) && !defined(CLASSIC))
/**
* Returns the amount of available specs the [Player] currently has
*
* @return uint8 specCount
*/
int GetSpecsCount(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSpecsCount());
return 1;
}
/**
* Returns the [Player]s active spec ID
*
* @return uint32 specId
*/
int GetActiveSpec(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetActiveSpec());
return 1;
}
#endif
#ifdef WOTLK
/**
* Returns the normal phase of the player instead of the actual phase possibly containing GM phase
*
* @return uint32 phasemask
*/
int GetPhaseMaskForSpawn(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetPhaseMaskForSpawn());
return 1;
}
#endif
#ifndef CATA
#ifndef CLASSIC
/**
* Returns the [Player]s current amount of Arena Points
*
* @return uint32 arenaPoints
*/
int GetArenaPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetArenaPoints());
return 1;
}
/**
* Returns the [Player]s current amount of Honor Points
*
* @return uint32 honorPoints
*/
int GetHonorPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetHonorPoints());
return 1;
}
#endif
/**
* Returns the [Player]s current shield block value
*
* @return uint32 blockValue
*/
int GetShieldBlockValue(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetShieldBlockValue());
return 1;
}
#endif
/**
* Returns the [Player]s cooldown delay by specified [Spell] ID
*
* @param uint32 spellId
* @return uint32 spellCooldownDelay
*/
int GetSpellCooldownDelay(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
#ifdef TRINITY
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
Eluna::Push(L, player->GetSpellHistory()->GetRemainingCooldown(spellInfo));
else
Eluna::Push(L, 0);
#else
Eluna::Push(L, uint32(player->GetSpellCooldownDelay(spellId)));
#endif
return 1;
}
/**
* Returns the [Player]s current latency in MS
*
* @return uint32 latency
*/
int GetLatency(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetLatency());
return 1;
}
#ifdef TRINITY
/**
* Returns the faction ID the [Player] is currently flagged as champion for
*
* @return uint32 championingFaction
*/
int GetChampioningFaction(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetChampioningFaction());
return 1;
}
#endif
/**
* Returns [Player]s original sub group
*
* @return uint8 subGroup
*/
int GetOriginalSubGroup(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetOriginalSubGroup());
return 1;
}
/**
* Returns [Player]s original [Group] object
*
* @return [Group] group
*/
int GetOriginalGroup(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetOriginalGroup());
return 1;
}
/**
* Returns a random Raid Member [Player] object within radius specified of [Player]
*
* @param float radius
* @return [Player] player
*/
int GetNextRandomRaidMember(Eluna* /*E*/, lua_State* L, Player* player)
{
float radius = Eluna::CHECKVAL<float>(L, 2);
Eluna::Push(L, player->GetNextRandomRaidMember(radius));
return 1;
}
/**
* Returns [Player]s current sub group
*
* @return uint8 subGroup
*/
int GetSubGroup(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSubGroup());
return 1;
}
/**
* Returns [Group] invitation
*
* @return [Group] group
*/
int GetGroupInvite(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetGroupInvite());
return 1;
}
/**
* Returns rested experience bonus
*
* @param uint32 xp
* @return uint32 xpBonus
*/
int GetXPRestBonus(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 xp = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetXPRestBonus(xp));
return 1;
}
/**
* Returns the [Player]s current [BattleGround] type ID
*
* @return [BattleGroundTypeId] typeId
*/
int GetBattlegroundTypeId(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->GetBattleGroundTypeId());
#else
Eluna::Push(L, player->GetBattlegroundTypeId());
#endif
return 1;
}
/**
* Returns the [Player]s current [BattleGround] ID
*
* @return uint32 battleGroundId
*/
int GetBattlegroundId(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->GetBattleGroundId());
#else
Eluna::Push(L, player->GetBattlegroundId());
#endif
return 1;
}
/**
* Returns the [Player]s reputation rank of faction specified
*
* @param uint32 faction
* @return [ReputationRank] rank
*/
int GetReputationRank(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 faction = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetReputationRank(faction));
return 1;
}
/**
* Returns the [Player]s current level of intoxication
*
* @return uint16 drunkValue
*/
int GetDrunkValue(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetDrunkValue());
return 1;
}
/**
* Returns skill temporary bonus value
*
* @param uint32 skill
* @param int16 bonusVal
*/
int GetSkillTempBonusValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetSkillTempBonusValue(skill));
return 1;
}
/**
* Returns skill permanent bonus value
*
* @param uint32 skill
* @param int16 bonusVal
*/
int GetSkillPermBonusValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetSkillPermBonusValue(skill));
return 1;
}
/**
* Returns skill value without bonus'
*
* @param uint32 skill
* @return uint16 pureVal
*/
int GetPureSkillValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetPureSkillValue(skill));
return 1;
}
/**
* Returns base skill value
*
* @param uint32 skill
* @return uint16 baseVal
*/
int GetBaseSkillValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetBaseSkillValue(skill));
return 1;
}
/**
* Returns skill value
*
* @param uint32 skill
* @return uint16 val
*/
int GetSkillValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetSkillValue(skill));
return 1;
}
/**
* Returns max value of specified skill without bonus'
*
* @param uint32 skill
* @return uint16 pureVal
*/
int GetPureMaxSkillValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetPureMaxSkillValue(skill));
return 1;
}
/**
* Returns max value of specified skill
*
* @param uint32 skill
* @return uint16 val
*/
int GetMaxSkillValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 skill = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetMaxSkillValue(skill));
return 1;
}
/**
* Returns mana bonus from amount of intellect
*
* @return float bonus
*/
int GetManaBonusFromIntellect(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetManaBonusFromIntellect());
return 1;
}
/**
* Returns health bonus from amount of stamina
*
* @return float bonus
*/
int GetHealthBonusFromStamina(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetHealthBonusFromStamina());
return 1;
}
/**
* Returns raid or dungeon difficulty
*
* @param bool isRaid = true : argument is TrinityCore only
* @return int32 difficulty
*/
int GetDifficulty(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifdef TBC
Eluna::Push(L, player->GetDifficulty());
#elif defined(CLASSIC)
Eluna::Push(L, (Difficulty)0);
#else
bool isRaid = Eluna::CHECKVAL<bool>(L, 2, true);
Eluna::Push(L, player->GetDifficulty(isRaid));
#endif
return 1;
}
/**
* Returns the [Player]s current guild rank
*
* @return uint32 guildRank
*/
int GetGuildRank(Eluna* /*E*/, lua_State* L, Player* player) // TODO: Move to Guild Methods
{
Eluna::Push(L, player->GetRank());
return 1;
}
/**
* Returns the [Player]s free talent point amount
*
* @return uint32 freeTalentPointAmt
*/
int GetFreeTalentPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetFreeTalentPoints());
return 1;
}
/**
* Returns the name of the [Player]s current [Guild]
*
* @return string guildName
*/
int GetGuildName(Eluna* /*E*/, lua_State* L, Player* player)
{
if (!player->GetGuildId())
return 1;
Eluna::Push(L, eGuildMgr->GetGuildNameById(player->GetGuildId()));
return 1;
}
/**
* Returns the amount of reputation the [Player] has with the faction specified
*
* @param uint32 faction
* @return int32 reputationAmt
*/
int GetReputation(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 faction = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetReputationMgr().GetReputation(faction));
return 1;
}
/**
* Returns [Unit] target combo points are on
*
* @return [Unit] target
*/
int GetComboTarget(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->GetMap()->GetUnit(player->GetComboTargetGuid()));
#else
Eluna::Push(L, ObjectAccessor::GetUnit(*player, player->GetComboTarget()));
#endif
return 1;
}
/**
* Returns [Player]'s combo points
*
* @return uint8 comboPoints
*/
int GetComboPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetComboPoints());
return 1;
}
/**
* Returns the amount of time the [Player] has spent ingame
*
* @return uint32 inGameTime
*/
int GetInGameTime(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetInGameTime());
return 1;
}
/**
* Returns the status of the [Player]s [Quest] specified by entry ID
*
* @param uint32 questId
* @return [QuestStatus] questStatus
*/
int GetQuestStatus(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetQuestStatus(entry));
return 1;
}
/**
* Returns 'true' if the [Player]s [Quest] specified by entry ID has been rewarded, 'false' otherwise.
*
* @param uint32 questId
* @return bool questRewardStatus
*/
int GetQuestRewardStatus(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetQuestRewardStatus(questId));
return 1;
}
/**
* Returns [Quest] required [Creature] or [GameObject] count
*
* @param uint32 quest : entry of a quest
* @param int32 entry : entry of required [Creature]
* @return uint16 count
*/
int GetReqKillOrCastCurrentCount(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
int32 entry = Eluna::CHECKVAL<int32>(L, 3);
Eluna::Push(L, player->GetReqKillOrCastCurrentCount(questId, entry));
return 1;
}
/**
* Returns the quest level of the [Player]s [Quest] specified by object
*
* @param uint32 questId
* @return [QuestStatus] questRewardStatus
*/
int GetQuestLevel(Eluna* /*E*/, lua_State* L, Player* player)
{
Quest* quest = Eluna::CHECKOBJ<Quest>(L, 2);
#ifndef TRINITY
Eluna::Push(L, player->GetQuestLevelForPlayer(quest));
#else
Eluna::Push(L, player->GetQuestLevel(quest));
#endif
return 1;
}
/**
* Returns a [Player]s [Item] object by gear slot specified
*
* @param uint8 slot
* @return [Item] item
*/
int GetEquippedItemBySlot(Eluna* /*E*/, lua_State* L, Player* player)
{
uint8 slot = Eluna::CHECKVAL<uint8>(L, 2);
if (slot >= EQUIPMENT_SLOT_END)
return 1;
Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
Eluna::Push(L, item);
return 1;
}
/**
* Returns the [Player]s current resting bonus
*
* @return float restBonus
*/
int GetRestBonus(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetRestBonus());
return 1;
}
/**
* Returns active GM chat tag
*
* @return uint8 tag
*/
int GetChatTag(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetChatTag());
return 1;
}
/**
* Returns an item in given bag on given slot.
*
* <pre>
* Possible and most commonly used combinations:
*
* bag = 255
* slots 0-18 equipment
* slots 19-22 equipped bag slots
* slots 23-38 backpack
* slots 39-66 bank main slots
* slots 67-74 bank bag slots
* slots 86-117 keyring
*
* bag = 19-22
* slots 0-35 for equipped bags
*
* bag = 67-74
* slots 0-35 for bank bags
* </pre>
*
* @param uint8 bag : the bag the [Item] is in, you can get this with [Item:GetBagSlot]
* @param uint8 slot : the slot the [Item] is in within the bag, you can get this with [Item:GetSlot]
* @return [Item] item : [Item] or nil
*/
int GetItemByPos(Eluna* /*E*/, lua_State* L, Player* player)
{
uint8 bag = Eluna::CHECKVAL<uint8>(L, 2);
uint8 slot = Eluna::CHECKVAL<uint8>(L, 3);
Eluna::Push(L, player->GetItemByPos(bag, slot));
return 1;
}
/**
* Returns an [Item] from the player by guid.
*
* The item can be equipped, in bags or in bank.
*
* @param uint64 guid : an item guid
* @return [Item] item
*/
int GetItemByGUID(Eluna* /*E*/, lua_State* L, Player* player)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2);
Eluna::Push(L, player->GetItemByGuid(ObjectGuid(guid)));
return 1;
}
/**
* Returns an [Item] from the player by entry.
*
* The item can be equipped, in bags or in bank.
*
* @param uint32 entryId
* @return [Item] item
*/
int GetItemByEntry(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->GetItemByEntry(entry));
return 1;
}
/**
* Returns the database textID of the [WorldObject]'s gossip header text for the [Player]
*
* @return uint32 textId : key to npc_text database table
*/
int GetGossipTextId(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 2);
Eluna::Push(L, player->GetGossipTextId(obj));
return 1;
}
/**
* Returns the [Player]s currently selected [Unit] object
*
* @return [Unit] unit
*/
int GetSelection(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifndef TRINITY
Eluna::Push(L, player->GetMap()->GetUnit(player->GetSelectionGuid()));
#else
Eluna::Push(L, player->GetSelectedUnit());
#endif
return 1;
}
/**
* Returns the [Player]s GM Rank
*
* @return [AccountTypes] gmRank
*/
int GetGMRank(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetSecurity());
return 1;
}
/**
* Returns the [Player]s amount of money in copper
*
* @return uint32 coinage
*/
int GetCoinage(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetMoney());
return 1;
}
/**
* Returns the [Player]s current [Guild] ID
*
* @return uint32 guildId
*/
int GetGuildId(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetGuildId());
return 1;
}
/**
* Returns the [Player]s [TeamId]
*
* @return [TeamId] teamId
*/
int GetTeam(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetTeamId());
return 1;
}
/**
* Returns amount of the specified [Item] the [Player] has.
*
* @param uint32 entry : entry of the item
* @param bool checkinBank = false : also counts the items in player's bank if true
* @return uint32 itemamount
*/
int GetItemCount(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
bool checkinBank = Eluna::CHECKVAL<bool>(L, 3, false);
Eluna::Push(L, player->GetItemCount(entry, checkinBank));
return 1;
}
/**
* Returns the [Player]s lifetime Honorable Kills
*
* @return uint32 lifeTimeKils
*/
int GetLifetimeKills(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS));
return 1;
}
/**
* Returns the [Player]s IP address
*
* @return string ip
*/
int GetPlayerIP(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetRemoteAddress());
return 1;
}
/**
* Returns the [Player]s time played at current level
*
* @return uint32 currLevelPlayTime
*/
int GetLevelPlayedTime(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetLevelPlayedTime());
return 1;
}
/**
* Returns the [Player]s total time played
*
* @return uint32 totalPlayTime
*/
int GetTotalPlayedTime(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetTotalPlayedTime());
return 1;
}
/**
* Returns the [Player]s [Guild] object
*
* @return [Guild] guild
*/
int GetGuild(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, eGuildMgr->GetGuildById(player->GetGuildId()));
return 1;
}
/**
* Returns the [Player]s [Group] object
*
* @return [Group] group
*/
int GetGroup(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetGroup());
return 1;
}
/**
* Returns the [Player]s account ID
*
* @return uint32 accountId
*/
int GetAccountId(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetAccountId());
return 1;
}
/**
* Returns the [Player]s account name
*
* @return string accountName
*/
int GetAccountName(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string accName;
if (eAccountMgr->GetName(player->GetSession()->GetAccountId(), accName))
Eluna::Push(L, accName);
return 1;
}
/**
* Returns the [Player]s [Corpse] object
*
* @return [Corpse] corpse
*/
int GetCorpse(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetCorpse());
return 1;
}
/**
* Returns the [Player]s database locale index
*
* @return int localeIndex
*/
int GetDbLocaleIndex(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetSessionDbLocaleIndex());
return 1;
}
/**
* Returns the [Player]s game client locale
*
* @return [LocaleConstant] locale
*/
int GetDbcLocale(Eluna* /*E*/, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetSessionDbcLocale());
return 1;
}
/*int GetRecruiterId(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSession()->GetRecruiterId());
return 1;
}*/
/*int GetSelectedPlayer(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSelectedPlayer());
return 1;
}*/
/*int GetSelectedUnit(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, player->GetSelectedUnit());
return 1;
}*/
/*int GetNearbyGameObject(Eluna* E, lua_State* L, Player* player)
{
Eluna::Push(L, ChatHandler(player->GetSession()).GetNearbyGameObject());
return 1;
}*/
/**
* Locks the player controls and disallows all movement and casting.
*
* @param bool apply = true : lock if true and unlock if false
*/
int SetPlayerLock(Eluna* /*E*/, lua_State* L, Player* player)
{
bool apply = Eluna::CHECKVAL<bool>(L, 2, true);
if (apply)
{
player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED | UNIT_FLAG_SILENCED);
player->SetClientControl(player, 0);
}
else
{
player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED | UNIT_FLAG_SILENCED);
player->SetClientControl(player, 1);
}
return 0;
}
/**
* Sets the [Player]s login flag to the flag specified
*
* @param uint32 flag
*/
int SetAtLoginFlag(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 flag = Eluna::CHECKVAL<uint32>(L, 2);
player->SetAtLoginFlag((AtLoginFlags)flag);
return 0;
}
/**
* Sets the [Player]s sheathe state to the state specified
*
* @param uint32 sheatheState
*/
int SetSheath(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 sheathed = Eluna::CHECKVAL<uint32>(L, 2);
if (sheathed >= MAX_SHEATH_STATE)
return 0;
player->SetSheath((SheathState)sheathed);
return 0;
}
/**
* Sets the [Player]s intoxication level to the level specified
*
* @param uint8 drunkValue
*/
int SetDrunkValue(Eluna* /*E*/, lua_State* L, Player* player)
{
uint8 newDrunkValue = Eluna::CHECKVAL<uint8>(L, 2);
player->SetDrunkValue(newDrunkValue);
return 0;
}
/**
* Sets the [Player]s faction standing to that of the race specified
*
* @param uint8 raceId
*/
int SetFactionForRace(Eluna* /*E*/, lua_State* L, Player* player)
{
uint8 race = Eluna::CHECKVAL<uint8>(L, 2);
player->setFactionForRace(race);
return 0;
}
/**
* Sets (increases) skill of the [Player]
*
* @param uint16 id
* @param uint16 step
* @param uint16 currVal
* @param uint16 maxVal
*/
int SetSkill(Eluna* /*E*/, lua_State* L, Player* player)
{
uint16 id = Eluna::CHECKVAL<uint16>(L, 2);
uint16 step = Eluna::CHECKVAL<uint16>(L, 3);
uint16 currVal = Eluna::CHECKVAL<uint16>(L, 4);
uint16 maxVal = Eluna::CHECKVAL<uint16>(L, 5);
player->SetSkill(id, step, currVal, maxVal);
return 0;
}
/**
* Sets the [Player]s guild rank to the rank specified
*
* @param uint8 rank
*/
int SetGuildRank(Eluna* /*E*/, lua_State* L, Player* player) // TODO: Move to Guild Methods
{
uint8 rank = Eluna::CHECKVAL<uint8>(L, 2);
if (!player->GetGuildId())
return 0;
player->SetRank(rank);
return 0;
}
/**
* Sets the [Player]s free talent points to the amount specified for the current spec
*
* @param uint32 talentPointAmt
*/
int SetFreeTalentPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 points = Eluna::CHECKVAL<uint32>(L, 2);
player->SetFreeTalentPoints(points);
#if (!defined(TBC) && !defined(CLASSIC))
player->SendTalentsInfoData(false);
#endif
return 0;
}
/**
* Sets the [Player]s reputation amount for the faction specified
*
* @param uint32 factionId
* @param int32 reputationValue
*/
int SetReputation(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 faction = Eluna::CHECKVAL<uint32>(L, 2);
int32 value = Eluna::CHECKVAL<int32>(L, 3);
FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction);
player->GetReputationMgr().SetReputation(factionEntry, value);
return 0;
}
/**
* Sets [Quest] state
*
* @param uint32 entry : entry of a quest
* @param uint32 status
*/
int SetQuestStatus(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
uint32 status = Eluna::CHECKVAL<uint32>(L, 3);
if (status >= MAX_QUEST_STATUS)
return 0;
player->SetQuestStatus(entry, (QuestStatus)status);
return 0;
}
/**
* Sets the [Player]s rest bonus to the amount specified
*
* @param float restBonus
*/
int SetRestBonus(Eluna* /*E*/, lua_State* L, Player* player)
{
float bonus = Eluna::CHECKVAL<float>(L, 2);
player->SetRestBonus(bonus);
return 0;
}
/**
* Toggles whether the [Player] accepts whispers or not
*
* @param bool acceptWhispers = true
*/
int SetAcceptWhispers(Eluna* /*E*/, lua_State* L, Player* player)
{
bool on = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetAcceptWhispers(on);
return 0;
}
/**
* Toggles PvP Death
*
* @param bool on = true
*/
int SetPvPDeath(Eluna* /*E*/, lua_State* L, Player* player)
{
bool on = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetPvPDeath(on);
return 0;
}
/**
* Toggles whether the [Player] has GM visibility on or off
*
* @param bool gmVisible = true
*/
int SetGMVisible(Eluna* /*E*/, lua_State* L, Player* player)
{
bool on = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetGMVisible(on);
return 0;
}
/**
* Toggles whether the [Player] has taxi cheat enabled or not
*
* @param bool taxiCheat = true
*/
int SetTaxiCheat(Eluna* /*E*/, lua_State* L, Player* player)
{
bool on = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetTaxiCheater(on);
return 0;
}
/**
* Toggle Blizz (GM) tag
*
* @param bool on = true
*/
int SetGMChat(Eluna* /*E*/, lua_State* L, Player* player)
{
bool on = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetGMChat(on);
return 0;
}
/**
* Toggles the [Player]s GM mode on or off
*
* @param bool setGmMode = true
*/
int SetGameMaster(Eluna* /*E*/, lua_State* L, Player* player)
{
bool on = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetGameMaster(on);
return 0;
}
/**
* Sets the [Player]s gender to gender specified
*
* - GENDER_MALE = 0
* - GENDER_FEMALE = 1
*
* @param [Gender] gender
*/
int SetGender(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 _gender = Eluna::CHECKVAL<uint32>(L, 2);
Gender gender;
switch (_gender)
{
case 0:
gender = GENDER_MALE;
break;
case 1:
gender = GENDER_FEMALE;
break;
default:
return luaL_argerror(L, 2, "valid Gender expected");
}
player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
player->SetByteValue(PLAYER_BYTES_3, 0, gender);
player->InitDisplayIds();
return 0;
}
#ifndef CATA
#ifndef CLASSIC
/**
* Sets the [Player]s Arena Points to the amount specified
*
* @param uint32 arenaPoints
*/
int SetArenaPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 arenaP = Eluna::CHECKVAL<uint32>(L, 2);
player->SetArenaPoints(arenaP);
return 0;
}
/**
* Sets the [Player]s Honor Points to the amount specified
*
* @param uint32 honorPoints
*/
int SetHonorPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 honorP = Eluna::CHECKVAL<uint32>(L, 2);
player->SetHonorPoints(honorP);
return 0;
}
#endif
#endif
#ifdef CLASSIC
/**
* Sets kills
*
* @param uint32 kills
* @param bool honorable = true : if victims were honorable
*/
int SetHonorStoredKills(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 kills = Eluna::CHECKVAL<uint32>(L, 2);
bool honorable = Eluna::CHECKVAL<bool>(L, 3, true);
player->SetHonorStoredKills(kills, honorable);
return 0;
}
/**
* Sets rank points
*
* @param float rankPoints
*/
int SetRankPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
float rankPoints = Eluna::CHECKVAL<float>(L, 2);
player->SetRankPoints(rankPoints);
return 0;
}
/**
* Sets last week's honor standing position
*
* @param int32 standingPos
*/
int SetHonorLastWeekStandingPos(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 standingPos = Eluna::CHECKVAL<int32>(L, 2);
player->SetHonorLastWeekStandingPos(standingPos);
return 0;
}
#endif
/**
* Sets the [Player]s amount of Lifetime Honorable Kills to the value specified
*
* @param uint32 honorableKills
*/
int SetLifetimeKills(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 val = Eluna::CHECKVAL<uint32>(L, 2);
player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, val);
return 0;
}
/**
* Sets the [Player]s amount of money to copper specified
*
* @param uint32 copperAmt
*/
int SetCoinage(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 amt = Eluna::CHECKVAL<uint32>(L, 2);
player->SetMoney(amt);
return 0;
}
/**
* Sets the [Player]s home location to the location specified
*
* @param float x : X Coordinate
* @param float y : Y Coordinate
* @param float z : Z Coordinate
* @param uint32 mapId : Map ID
* @param uint32 areaId : Area ID
*/
int SetBindPoint(Eluna* /*E*/, lua_State* L, Player* player)
{
float x = Eluna::CHECKVAL<float>(L, 2);
float y = Eluna::CHECKVAL<float>(L, 3);
float z = Eluna::CHECKVAL<float>(L, 4);
uint32 mapId = Eluna::CHECKVAL<uint32>(L, 5);
uint32 areaId = Eluna::CHECKVAL<uint32>(L, 6);
WorldLocation loc(mapId, x, y, z);
#ifndef TRINITY
player->SetHomebindToLocation(loc, areaId);
#else
player->SetHomebind(loc, areaId);
#endif
return 0;
}
#ifndef CLASSIC
/**
* Adds the specified title to the [Player]s list of known titles
*
* @param uint32 titleId
*/
int SetKnownTitle(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id);
if (t)
player->SetTitle(t, false);
return 0;
}
#endif
#ifndef TRINITY
/**
* Toggle the [Player]s FFA flag
*
* @param bool applyFFA = true
*/
int SetFFA(Eluna* /*E*/, lua_State* L, Player* player)
{
bool apply = Eluna::CHECKVAL<bool>(L, 2, true);
player->SetFFAPvP(apply);
return 0;
}
#endif
/*int SetMovement(Eluna* E, lua_State* L, Player* player)
{
int32 pType = Eluna::CHECKVAL<int32>(L, 2);
player->SetMovement((PlayerMovementType)pType);
return 0;
}*/
#if (!defined(TBC) && !defined(CLASSIC))
/**
* Resets the [Player]s pets talent points
*/
int ResetPetTalents(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifndef TRINITY
Pet* pet = player->GetPet();
Pet::resetTalentsForAllPetsOf(player, pet);
if (pet)
player->SendTalentsInfoData(true);
#else
player->ResetPetTalents();
player->SendTalentsInfoData(true);
#endif
return 0;
}
/**
* Reset the [Player]s completed achievements
*/
int ResetAchievements(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifndef TRINITY
player->GetAchievementMgr().Reset();
#else
player->ResetAchievements();
#endif
return 0;
}
#endif
/**
* Shows the mailbox window to the player from specified guid.
*
* @param uint64 guid = playerguid : guid of the mailbox window sender
*/
int SendShowMailBox(Eluna* /*E*/, lua_State* L, Player* player)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2, player->GET_GUID());
#if (defined(CLASSIC) || defined(TBC))
WorldPacket data(CMSG_GET_MAIL_LIST, 8);
data << uint64(guid);
player->GetSession()->HandleGetMailList(data);
#else
player->GetSession()->SendShowMailBox(ObjectGuid(guid));
#endif
return 0;
}
#ifndef CATA
#ifndef CLASSIC
/**
* Adds or detracts from the [Player]s current Arena Points
*
* @param int32 amount
*/
int ModifyArenaPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 amount = Eluna::CHECKVAL<int32>(L, 2);
player->ModifyArenaPoints(amount);
return 0;
}
/**
* Adds or detracts from the [Player]s current Honor Points
*
* @param int32 amount
*/
int ModifyHonorPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 amount = Eluna::CHECKVAL<int32>(L, 2);
player->ModifyHonorPoints(amount);
return 0;
}
#endif
#endif
/**
* Saves the [Player] to the database
*/
int SaveToDB(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->SaveToDB();
return 0;
}
/**
* Sends a summon request popup for the given [Player] to the given location
*
* @param [Player] target : player to summon
* @param uint32 map
* @param float x
* @param float y
* @param float z
* @param uint32 zoneId
* @param uint32 delay = 2*MINUTE : time for the popup to be available for the target in milliseconds
*/
int SummonPlayer(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* target = Eluna::CHECKOBJ<Player>(L, 2);
uint32 map = Eluna::CHECKVAL<uint32>(L, 3);
float x = Eluna::CHECKVAL<float>(L, 4);
float y = Eluna::CHECKVAL<float>(L, 5);
float z = Eluna::CHECKVAL<float>(L, 6);
uint32 zoneId = Eluna::CHECKVAL<uint32>(L, 7);
uint32 delay = Eluna::CHECKVAL<uint32>(L, 8, MAX_PLAYER_SUMMON_DELAY * IN_MILLISECONDS);
if (!MapManager::IsValidMapCoord(map, x, y, z))
return 0;
target->SetSummonPoint(map, x, y, z);
WorldPacket data(SMSG_SUMMON_REQUEST, 8 + 4 + 4);
#ifdef TRINITY
data << uint64(player->GetGUID().GetCounter());
#else
data << uint64(player->GetGUIDLow());
#endif
data << uint32(zoneId);
data << uint32(delay);
target->GetSession()->SendPacket(&data);
return 0;
}
/**
* Mutes the [Player] for the amount of seconds specified
*
* @param uint32 muteTime
*/
int Mute(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 muteseconds = Eluna::CHECKVAL<uint32>(L, 2);
/*const char* reason = luaL_checkstring(E, 2);*/ // Mangos does not have a reason field in database.
time_t muteTime = time(NULL) + muteseconds;
player->GetSession()->m_muteTime = muteTime;
std::ostringstream oss;
oss << "UPDATE account SET mutetime = " << muteTime << " WHERE id = " << player->GetSession()->GetAccountId();
LoginDatabase.PExecute("%s", oss.str().c_str());
return 0;
}
/**
* Creates the [Player]'s corpse
*/
int CreateCorpse(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->CreateCorpse();
return 0;
}
/**
* Rewards the given quest entry for the [Player] if he has completed it.
*
* @param uint32 entry : quest entry
*/
int RewardQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Quest const* quest = eObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE)
return 0;
player->RewardQuest(quest, 0, player);
return 0;
}
/**
* Sends an auction house window to the [Player] from the [Unit] specified
*
* @param [Unit] sender
*/
int SendAuctionMenu(Eluna* /*E*/, lua_State* L, Player* player)
{
Unit* unit = Eluna::CHECKOBJ<Unit>(L, 2);
#ifndef TRINITY
AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit);
#else
AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction());
#endif
if (!ahEntry)
return 0;
WorldPacket data(MSG_AUCTION_HELLO, 12);
#ifdef TRINITY
data << uint64(unit->GetGUID().GetCounter());
#else
data << uint64(unit->GetGUIDLow());
#endif
data << uint32(ahEntry->houseId);
data << uint8(1);
player->GetSession()->SendPacket(&data);
return 0;
}
/**
* Sends a flightmaster window to the [Player] from the [Creature] specified
*
* @param [Creature] sender
*/
int SendTaxiMenu(Eluna* /*E*/, lua_State* L, Player* player)
{
Creature* creature = Eluna::CHECKOBJ<Creature>(L, 2);
player->GetSession()->SendTaxiMenu(creature);
return 0;
}
/**
* Sends a spirit resurrection request to the [Player]
*/
int SendSpiritResurrect(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->GetSession()->SendSpiritResurrect();
return 0;
}
/**
* Sends a tabard vendor window to the [Player] from the [WorldObject] specified
*
* @param [WorldObject] sender
*/
int SendTabardVendorActivate(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 2);
player->GetSession()->SendTabardVendorActivate(obj->GET_GUID());
return 0;
}
/**
* Sends a bank window to the [Player] from the [WorldObject] specified.
*
* @param [WorldObject] sender
*/
int SendShowBank(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 2);
player->GetSession()->SendShowBank(obj->GET_GUID());
return 0;
}
/**
* Sends a vendor window to the [Player] from the [WorldObject] specified.
*
* @param [WorldObject] sender
*/
int SendListInventory(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 2);
player->GetSession()->SendListInventory(obj->GET_GUID());
return 0;
}
/**
* Sends a trainer window to the [Player] from the [WorldObject] specified
*
* @param [WorldObject] sender
*/
int SendTrainerList(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 2);
player->GetSession()->SendTrainerList(obj->GET_GUID());
return 0;
}
/**
* Sends a guild invitation from the [Player]s [Guild] to the [Player] object specified
*
* @param [Player] invitee
*/
int SendGuildInvite(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* plr = Eluna::CHECKOBJ<Player>(L, 2);
#ifndef TRINITY
player->GetSession()->SendGuildInvite(plr);
#else
if (Guild* guild = player->GetGuild())
guild->HandleInviteMember(player->GetSession(), plr->GetName());
#endif
return 0;
}
/**
* Forces the [Player] to log out
*
* @param bool saveToDb = true
*/
int LogoutPlayer(Eluna* /*E*/, lua_State* L, Player* player)
{
bool save = Eluna::CHECKVAL<bool>(L, 2, true);
player->GetSession()->LogoutPlayer(save);
return 0;
}
/**
* Forcefully removes the [Player] from a [BattleGround] raid group
*/
int RemoveFromBattlegroundRaid(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifndef TRINITY
player->RemoveFromBattleGroundRaid();
#else
player->RemoveFromBattlegroundOrBattlefieldRaid();
#endif
return 0;
}
/**
* Unbinds the [Player] from his instances except the one he currently is in.
*
* Difficulty is not used on classic.
*
* @param uint32 map = true
* @param uint32 difficulty = 0
*/
int UnbindInstance(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 map = Eluna::CHECKVAL<uint32>(L, 2);
#ifndef CLASSIC
uint32 difficulty = Eluna::CHECKVAL<uint32>(L, 3, 0);
if (difficulty < MAX_DIFFICULTY)
player->UnbindInstance(map, (Difficulty)difficulty);
#else
player->UnbindInstance(map);
#endif
return 0;
}
/**
* Unbinds the [Player] from his instances except the one he currently is in.
*/
int UnbindAllInstances(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifdef CLASSIC
Player::BoundInstancesMap& binds = player->GetBoundInstances();
for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
{
if (itr->first != player->GetMapId())
player->UnbindInstance(itr);
else
++itr;
}
#else
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
Player::BoundInstancesMap& binds = player->GetBoundInstances(Difficulty(i));
for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
{
if (itr->first != player->GetMapId())
player->UnbindInstance(itr, Difficulty(i));
else
++itr;
}
}
#endif
return 0;
}
/**
* Forces the [Player] to leave a [BattleGround]
*
* @param bool teleToEntry = true
*/
int LeaveBattleground(Eluna* /*E*/, lua_State* L, Player* player)
{
bool teleToEntryPoint = Eluna::CHECKVAL<bool>(L, 2, true);
player->LeaveBattleground(teleToEntryPoint);
return 0;
}
/**
* Repairs [Item] at specified position. Returns total repair cost
*
* @param uint16 position
* @param bool cost = true
* @param float discountMod
* @param bool guildBank = false
* @return uint32 totalCost
*/
int DurabilityRepair(Eluna* /*E*/, lua_State* L, Player* player)
{
uint16 position = Eluna::CHECKVAL<uint16>(L, 2);
bool cost = Eluna::CHECKVAL<bool>(L, 3, true);
float discountMod = Eluna::CHECKVAL<float>(L, 4);
bool guildBank = Eluna::CHECKVAL<bool>(L, 5, false);
#ifdef CLASSIC
Eluna::Push(L, player->DurabilityRepair(position, cost, discountMod));
#else
Eluna::Push(L, player->DurabilityRepair(position, cost, discountMod, guildBank));
#endif
return 1;
}
/**
* Repairs all [Item]s. Returns total repair cost
*
* @param bool cost = true
* @param float discountMod = 1
* @param bool guidBank = false
* @return uint32 totalCost
*/
int DurabilityRepairAll(Eluna* /*E*/, lua_State* L, Player* player)
{
bool cost = Eluna::CHECKVAL<bool>(L, 2, true);
float discountMod = Eluna::CHECKVAL<float>(L, 3, 1.0f);
bool guildBank = Eluna::CHECKVAL<bool>(L, 4, false);
#ifdef CLASSIC
Eluna::Push(L, player->DurabilityRepairAll(cost, discountMod));
#else
Eluna::Push(L, player->DurabilityRepairAll(cost, discountMod, guildBank));
#endif
return 1;
}
/**
* Sets durability loss for an [Item] in the specified slot
*
* @param int32 slot
*/
int DurabilityPointLossForEquipSlot(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 slot = Eluna::CHECKVAL<int32>(L, 2);
if (slot >= EQUIPMENT_SLOT_START && slot < EQUIPMENT_SLOT_END)
player->DurabilityPointLossForEquipSlot((EquipmentSlots)slot);
return 0;
}
/**
* Sets durability loss on all [Item]s equipped
*
* If inventory is true, sets durability loss for [Item]s in bags
*
* @param int32 points
* @param bool inventory = true
*/
int DurabilityPointsLossAll(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 points = Eluna::CHECKVAL<int32>(L, 2);
bool inventory = Eluna::CHECKVAL<bool>(L, 3, true);
player->DurabilityPointsLossAll(points, inventory);
return 0;
}
/**
* Sets durability loss for the specified [Item]
*
* @param [Item] item
* @param int32 points
*/
int DurabilityPointsLoss(Eluna* /*E*/, lua_State* L, Player* player)
{
Item* item = Eluna::CHECKOBJ<Item>(L, 2);
int32 points = Eluna::CHECKVAL<int32>(L, 3);
player->DurabilityPointsLoss(item, points);
return 0;
}
/**
* Damages specified [Item]
*
* @param [Item] item
* @param double percent
*/
int DurabilityLoss(Eluna* /*E*/, lua_State* L, Player* player)
{
Item* item = Eluna::CHECKOBJ<Item>(L, 2);
double percent = Eluna::CHECKVAL<double>(L, 3);
player->DurabilityLoss(item, percent);
return 0;
}
/**
* Damages all [Item]s equipped. If inventory is true, damages [Item]s in bags
*
* @param double percent
* @param bool inventory = true
*/
int DurabilityLossAll(Eluna* /*E*/, lua_State* L, Player* player)
{
double percent = Eluna::CHECKVAL<double>(L, 2);
bool inventory = Eluna::CHECKVAL<bool>(L, 3, true);
player->DurabilityLossAll(percent, inventory);
return 0;
}
/**
* Kills the [Player]
*/
int KillPlayer(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->KillPlayer();
return 0;
}
/**
* Forces the [Player] to leave a [Group]
*/
int RemoveFromGroup(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
if (!player->GetGroup())
return 0;
player->RemoveFromGroup();
return 0;
}
/**
* Returns the [Player]s accumulated talent reset cost
*
* @return uint32 resetCost
*/
int ResetTalentsCost(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifdef CATA
Eluna::Push(L, player->GetNextResetTalentsCost());
#else
#ifdef TRINITY
Eluna::Push(L, player->ResetTalentsCost());
#else
Eluna::Push(L, player->resetTalentsCost());
#endif
#endif
return 1;
}
/**
* Resets the [Player]s talents
*
* @param bool noCost = true
*/
int ResetTalents(Eluna* /*E*/, lua_State* L, Player* player)
{
bool no_cost = Eluna::CHECKVAL<bool>(L, 2, true);
#ifdef CATA
player->ResetTalents(no_cost);
#else
#ifdef TRINITY
player->ResetTalents(no_cost);
#else
player->resetTalents(no_cost);
#endif
#endif
#if (!defined(TBC) && !defined(CLASSIC))
player->SendTalentsInfoData(false);
#endif
return 0;
}
/**
* Removes the [Spell] from the [Player]
*
* @param uint32 entry : entry of a [Spell]
* @param bool disabled = false
* @param bool learnLowRank = true
*/
int RemoveSpell(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
bool disabled = Eluna::CHECKVAL<bool>(L, 3, false);
bool learn_low_rank = Eluna::CHECKVAL<bool>(L, 4, true);
#ifdef TRINITY
player->RemoveSpell(entry, disabled, learn_low_rank);
#else
player->removeSpell(entry, disabled, learn_low_rank);
#endif
return 0;
}
/**
* Clears the [Player]s combo points
*/
int ClearComboPoints(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->ClearComboPoints();
return 0;
}
/**
* Adds combo points to the [Player]
*
* @param [Unit] target
* @param int8 count
*/
int AddComboPoints(Eluna* /*E*/, lua_State* L, Player* player)
{
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2);
int8 count = Eluna::CHECKVAL<int8>(L, 3);
player->AddComboPoints(target, count);
return 0;
}
/**
* Gives [Quest] monster talked to credit
*
* @param uint32 entry : entry of a [Creature]
* @param [Creature] creature
*/
int TalkedToCreature(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Creature* creature = Eluna::CHECKOBJ<Creature>(L, 3);
player->TalkedToCreature(entry, creature->GET_GUID());
return 0;
}
/**
* Gives [Quest] monster killed credit
*
* @param uint32 entry : entry of a [Creature]
*/
int KilledMonsterCredit(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
player->KilledMonsterCredit(entry, player->GET_GUID());
return 0;
}
/**
* Completes a [Quest] if in a [Group]
*
* @param uint32 quest : entry of a quest
* @param [WorldObject] obj
*/
int GroupEventHappens(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 3);
player->GroupEventHappens(questId, obj);
return 0;
}
/**
* Completes the [Quest] if a [Quest] area is explored, or completes the [Quest]
*
* @param uint32 quest : entry of a [Quest]
*/
int AreaExploredOrEventHappens(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
player->AreaExploredOrEventHappens(questId);
return 0;
}
/**
* Sets the given [Quest] entry failed for the [Player].
*
* @param uint32 entry : entry of a [Quest]
*/
int FailQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
player->FailQuest(entry);
return 0;
}
/**
* Sets the given quest entry incomplete for the [Player].
*
* @param uint32 entry : quest entry
*/
int IncompleteQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
player->IncompleteQuest(entry);
return 0;
}
/**
* Completes the given quest entry for the [Player] and tries to satisfy all quest requirements.
*
* The player should have the quest to complete it.
*
* @param uint32 entry : quest entry
*/
int CompleteQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Quest const* quest = eObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
return 0;
// Add quest items for quests that require items
for (uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
{
#ifdef TRINITY
uint32 id = quest->RequiredItemId[x];
uint32 count = quest->RequiredItemCount[x];
#else
uint32 id = quest->ReqItemId[x];
uint32 count = quest->ReqItemCount[x];
#endif
if (!id || !count)
continue;
uint32 curItemCount = player->GetItemCount(id, true);
ItemPosCountVec dest;
uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, id, count - curItemCount);
if (msg == EQUIP_ERR_OK)
{
Item* item = player->StoreNewItem(dest, id, true);
player->SendNewItem(item, count - curItemCount, true, false);
}
}
// All creature/GO slain/cast (not required, but otherwise it will display "Creature slain 0/10")
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
{
#ifdef TRINITY
int32 creature = quest->RequiredNpcOrGo[i];
uint32 creatureCount = quest->RequiredNpcOrGoCount[i];
if (creature > 0)
{
if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(creature))
for (uint16 z = 0; z < creatureCount; ++z)
player->KilledMonster(creatureInfo, ObjectGuid::Empty);
}
else if (creature < 0)
for (uint16 z = 0; z < creatureCount; ++z)
player->KillCreditGO(creature);
#else
int32 creature = quest->ReqCreatureOrGOId[i];
uint32 creaturecount = quest->ReqCreatureOrGOCount[i];
if (uint32 spell_id = quest->ReqSpell[i])
{
for (uint16 z = 0; z < creaturecount; ++z)
player->CastedCreatureOrGO(creature, ObjectGuid(), spell_id);
}
else if (creature > 0)
{
if (CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(creature))
for (uint16 z = 0; z < creaturecount; ++z)
player->KilledMonster(cInfo, ObjectGuid());
}
else if (creature < 0)
{
for (uint16 z = 0; z < creaturecount; ++z)
player->CastedCreatureOrGO(-creature, ObjectGuid(), 0);
}
#endif
}
// If the quest requires reputation to complete
if (uint32 repFaction = quest->GetRepObjectiveFaction())
{
uint32 repValue = quest->GetRepObjectiveValue();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue)
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry, repValue);
}
#ifdef TRINITY
// If the quest requires a SECOND reputation to complete
if (uint32 repFaction = quest->GetRepObjectiveFaction2())
{
uint32 repValue2 = quest->GetRepObjectiveValue2();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue2)
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry, repValue2);
}
#endif
// If the quest requires money
int32 ReqOrRewMoney = quest->GetRewOrReqMoney();
if (ReqOrRewMoney < 0)
player->ModifyMoney(-ReqOrRewMoney);
#ifdef TRINITY
if (sWorld->getBoolConfig(CONFIG_QUEST_ENABLE_QUEST_TRACKER)) // check if Quest Tracker is enabled
{
// prepare Quest Tracker datas
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_QUEST_TRACK_GM_COMPLETE);
stmt->setUInt32(0, quest->GetQuestId());
stmt->setUInt32(1, player->GetGUID().GetCounter());
// add to Quest Tracker
CharacterDatabase.Execute(stmt);
}
#endif
player->CompleteQuest(entry);
return 0;
}
/**
* Tries to add the given quest entry for the [Player].
*
* @param uint32 entry : quest entry
*/
int AddQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Quest const* quest = eObjectMgr->GetQuestTemplate(entry);
if (!quest)
return 0;
#ifdef TRINITY
// check item starting quest (it can work incorrectly if added without item in inventory)
ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore();
ItemTemplateContainer::const_iterator result = find_if(itc->begin(), itc->end(), Finder<uint32, ItemTemplate>(entry, &ItemTemplate::StartQuest));
if (result != itc->end())
return 0;
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(quest, true))
player->AddQuestAndCheckCompletion(quest, NULL);
#else
// check item starting quest (it can work incorrectly if added without item in inventory)
for (uint32 id = 0; id < sItemStorage.GetMaxEntry(); ++id)
{
ItemPrototype const* pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
if (!pProto)
continue;
if (pProto->StartQuest == entry)
return 0;
}
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(quest, true))
{
player->AddQuest(quest, NULL);
if (player->CanCompleteQuest(entry))
player->CompleteQuest(entry);
}
#endif
return 0;
}
/**
* Removes the given quest entry from the [Player].
*
* @param uint32 entry : quest entry
*/
int RemoveQuest(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
Quest const* quest = eObjectMgr->GetQuestTemplate(entry);
if (!quest)
return 0;
// remove all quest entries for 'entry' from quest log
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 logQuest = player->GetQuestSlotQuestId(slot);
if (logQuest == entry)
{
player->SetQuestSlot(slot, 0);
// we ignore unequippable quest items in this case, its' still be equipped
player->TakeQuestSourceItem(logQuest, false);
#ifdef TRINITY
if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
{
player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
player->UpdatePvPState();
}
#endif
}
}
#ifdef TRINITY
player->RemoveActiveQuest(entry, false);
player->RemoveRewardedQuest(entry);
#else
// set quest status to not started (will updated in DB at next save)
player->SetQuestStatus(entry, QUEST_STATUS_NONE);
// reset rewarded for restart repeatable quest
player->getQuestStatusMap()[entry].m_rewarded = false;
#endif
return 0;
}
/**
* Sends whisper text from the [Player]
*
* @param string text
* @param uint32 lang : language the [Player] will speak
* @param [Player] receiver : is the [Player] that will receive the whisper, if TrinityCore
* @param uint64 guid : is the GUID of a [Player] that will receive the whisper, not TrinityCore
*/
int Whisper(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string text = Eluna::CHECKVAL<std::string>(L, 2);
uint32 lang = Eluna::CHECKVAL<uint32>(L, 3);
#ifdef TRINITY
Player* receiver = Eluna::CHECKOBJ<Player>(L, 4);
#else
uint64 guid = Eluna::CHECKVAL<uint64>(L, 4);
#endif
#ifdef TRINITY
player->Whisper(text, (Language)lang, receiver);
#else
player->Whisper(text, lang, ObjectGuid(guid));
#endif
return 0;
}
/**
* Sends a text emote from the [Player]
*
* @param string emoteText
*/
int TextEmote(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string text = Eluna::CHECKVAL<std::string>(L, 2);
player->TextEmote(text);
return 0;
}
/**
* Sends yell text from the [Player]
*
* @param string text : text for the [Player] to yells
* @param uint32 lang : language the [Player] will speak
*/
int Yell(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string text = Eluna::CHECKVAL<std::string>(L, 2);
uint32 lang = Eluna::CHECKVAL<uint32>(L, 3);
#ifdef TRINITY
player->Yell(text, (Language)lang);
#else
player->Yell(text, lang);
#endif
return 0;
}
/**
* Sends say text from the [Player]
*
* @param string text : text for the [Player] to say
* @param uint32 lang : language the [Player] will speak
*/
int Say(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string text = Eluna::CHECKVAL<std::string>(L, 2);
uint32 lang = Eluna::CHECKVAL<uint32>(L, 3);
#ifdef TRINITY
player->Say(text, (Language)lang);
#else
player->Say(text, lang);
#endif
return 0;
}
/**
* Gives the [Player] experience
*
* @param uint32 xp : experience to give
* @param [Unit] victim = nil
*/
int GiveXP(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 xp = Eluna::CHECKVAL<uint32>(L, 2);
Unit* victim = Eluna::CHECKOBJ<Unit>(L, 3, false);
player->GiveXP(xp, victim);
return 0;
}
/**
* Toggle the [Player]s 'Do Not Disturb' flag
*/
int ToggleDND(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->ToggleDND();
return 0;
}
/**
* Toggle the [Player]s 'Away From Keyboard' flag
*/
int ToggleAFK(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->ToggleAFK();
return 0;
}
/**
* Equips the given item or item entry to the given slot. Returns the equipped item or nil.
*
* enum EquipmentSlots // 19 slots
* {
* EQUIPMENT_SLOT_START = 0,
* EQUIPMENT_SLOT_HEAD = 0,
* EQUIPMENT_SLOT_NECK = 1,
* EQUIPMENT_SLOT_SHOULDERS = 2,
* EQUIPMENT_SLOT_BODY = 3,
* EQUIPMENT_SLOT_CHEST = 4,
* EQUIPMENT_SLOT_WAIST = 5,
* EQUIPMENT_SLOT_LEGS = 6,
* EQUIPMENT_SLOT_FEET = 7,
* EQUIPMENT_SLOT_WRISTS = 8,
* EQUIPMENT_SLOT_HANDS = 9,
* EQUIPMENT_SLOT_FINGER1 = 10,
* EQUIPMENT_SLOT_FINGER2 = 11,
* EQUIPMENT_SLOT_TRINKET1 = 12,
* EQUIPMENT_SLOT_TRINKET2 = 13,
* EQUIPMENT_SLOT_BACK = 14,
* EQUIPMENT_SLOT_MAINHAND = 15,
* EQUIPMENT_SLOT_OFFHAND = 16,
* EQUIPMENT_SLOT_RANGED = 17,
* EQUIPMENT_SLOT_TABARD = 18,
* EQUIPMENT_SLOT_END = 19
* };
*
* enum InventorySlots // 4 slots
* {
* INVENTORY_SLOT_BAG_START = 19,
* INVENTORY_SLOT_BAG_END = 23
* };
*
* @proto equippedItem = (item, slot)
* @proto equippedItem = (entry, slot)
* @param [Item] item : item to equip
* @param uint32 entry : entry of the item to equip
* @param uint32 slot : equipment slot to equip the item to The slot can be [EquipmentSlots] or [InventorySlots]
* @return [Item] equippedItem : item or nil if equipping failed
*/
int EquipItem(Eluna* /*E*/, lua_State* L, Player* player)
{
uint16 dest = 0;
Item* item = Eluna::CHECKOBJ<Item>(L, 2, false);
uint32 slot = Eluna::CHECKVAL<uint32>(L, 3);
if (slot >= INVENTORY_SLOT_BAG_END)
return 1;
if (!item)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
item = Item::CreateItem(entry, 1, player);
if (!item)
return 1;
InventoryResult result = player->CanEquipItem(slot, dest, item, false);
if (result != EQUIP_ERR_OK)
{
delete item;
return 1;
}
player->ItemAddedQuestCheck(entry, 1);
#if (!defined(TBC) && !defined(CLASSIC))
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, entry, 1);
#endif
}
else
{
InventoryResult result = player->CanEquipItem(slot, dest, item, false);
if (result != EQUIP_ERR_OK)
return 1;
player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true);
}
Eluna::Push(L, player->EquipItem(dest, item, true));
player->AutoUnequipOffhandIfNeed();
return 1;
}
/**
* Returns true if the player can equip the given [Item] or item entry to the given slot, false otherwise.
*
* @proto canEquip = (item, slot)
* @proto canEquip = (entry, slot)
* @param [Item] item : item to equip
* @param uint32 entry : entry of the item to equip
* @param uint32 slot : equipment slot to test
* @return bool canEquip
*/
int CanEquipItem(Eluna* /*E*/, lua_State* L, Player* player)
{
Item* item = Eluna::CHECKOBJ<Item>(L, 2, false);
uint32 slot = Eluna::CHECKVAL<uint32>(L, 3);
if (slot >= EQUIPMENT_SLOT_END)
{
Eluna::Push(L, false);
return 1;
}
if (!item)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
uint16 dest;
InventoryResult msg = player->CanEquipNewItem(slot, dest, entry, false);
if (msg != EQUIP_ERR_OK)
{
Eluna::Push(L, false);
return 1;
}
}
else
{
uint16 dest;
InventoryResult msg = player->CanEquipItem(slot, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
Eluna::Push(L, false);
return 1;
}
}
Eluna::Push(L, true);
return 1;
}
#ifndef CLASSIC
/**
* Removes a title by ID from the [Player]s list of known titles
*
* @param uint32 titleId
*/
int UnsetKnownTitle(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id);
if (t)
player->SetTitle(t, true);
return 0;
}
#endif
/**
* Advances all of the [Player]s skills to the maximum amount available
*/
int AdvanceSkillsToMax(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->UpdateSkillsToMaxSkillsForLevel();
return 0;
}
/**
* Advances all of the [Player]s skills to the amount specified
*
* @param uint32 skillStep
*/
int AdvanceAllSkills(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 step = Eluna::CHECKVAL<uint32>(L, 2);
if (!step)
return 0;
static const uint32 skillsArray[] = { SKILL_BOWS, SKILL_CROSSBOWS, SKILL_DAGGERS, SKILL_DEFENSE, SKILL_UNARMED, SKILL_GUNS, SKILL_AXES, SKILL_MACES, SKILL_SWORDS, SKILL_POLEARMS,
SKILL_STAVES, SKILL_2H_AXES, SKILL_2H_MACES, SKILL_2H_SWORDS, SKILL_WANDS, SKILL_SHIELD, SKILL_FISHING, SKILL_MINING, SKILL_ENCHANTING, SKILL_BLACKSMITHING,
SKILL_ALCHEMY, SKILL_HERBALISM, SKILL_ENGINEERING, SKILL_LEATHERWORKING, SKILL_LOCKPICKING, SKILL_SKINNING, SKILL_TAILORING,
#ifndef CLASSIC
SKILL_JEWELCRAFTING,
#endif
#if (!defined(TBC) && !defined(CLASSIC))
SKILL_INSCRIPTION,
#endif
};
static const uint32 skillsSize = sizeof(skillsArray) / sizeof(*skillsArray);
for (uint32 i = 0; i < skillsSize; ++i)
{
if (player->HasSkill(skillsArray[i]))
player->UpdateSkill(skillsArray[i], step);
}
return 0;
}
/**
* Advances a [Player]s specific skill to the amount specified
*
* @param uint32 skillId
* @param uint32 skillStep
*/
int AdvanceSkill(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 _skillId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 _step = Eluna::CHECKVAL<uint32>(L, 3);
if (_skillId && _step)
{
if (player->HasSkill(_skillId))
player->UpdateSkill(_skillId, _step);
}
return 0;
}
/**
* Teleports a [Player] to the location specified
*
* @param uint32 mappId
* @param float xCoord
* @param float yCoord
* @param float zCoord
* @param float orientation
*/
int Teleport(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 mapId = Eluna::CHECKVAL<uint32>(L, 2);
float x = Eluna::CHECKVAL<float>(L, 3);
float y = Eluna::CHECKVAL<float>(L, 4);
float z = Eluna::CHECKVAL<float>(L, 5);
float o = Eluna::CHECKVAL<float>(L, 6);
#ifndef TRINITY
if (player->IsTaxiFlying())
#else
if (player->IsInFlight())
#endif
{
player->GetMotionMaster()->MovementExpired();
player->m_taxi.ClearTaxiDestinations();
}
Eluna::Push(L, player->TeleportTo(mapId, x, y, z, o));
return 1;
}
int AddLifetimeKills(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 val = Eluna::CHECKVAL<uint32>(L, 2);
uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS);
player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, currentKills + val);
return 0;
}
/**
* Adds the given amount of the specified item entry to the player.
*
* @param uint32 entry : entry of the item to add
* @param uint32 itemCount = 1 : amount of the item to add
* @return [Item] item : the item that was added or nil
*/
int AddItem(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 itemId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 itemCount = Eluna::CHECKVAL<uint32>(L, 3, 1);
#ifndef TRINITY
Eluna::Push(L, player->StoreNewItemInInventorySlot(itemId, itemCount));
#else
uint32 noSpaceForCount = 0;
ItemPosCountVec dest;
InventoryResult msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, itemCount, &noSpaceForCount);
if (msg != EQUIP_ERR_OK)
itemCount -= noSpaceForCount;
if (itemCount == 0 || dest.empty())
return 1;
Item* item = player->StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
if (item)
player->SendNewItem(item, itemCount, true, false);
Eluna::Push(L, item);
#endif
return 1;
}
/**
* Removes the given amount of the specified [Item] from the player.
*
* @proto (item, itemCount)
* @proto (entry, itemCount)
* @param [Item] item : item to remove
* @param uint32 entry : entry of the item to remove
* @param uint32 itemCount = 1 : amount of the item to remove
*/
int RemoveItem(Eluna* /*E*/, lua_State* L, Player* player)
{
Item* item = Eluna::CHECKOBJ<Item>(L, 2, false);
uint32 itemCount = Eluna::CHECKVAL<uint32>(L, 3);
if (!item)
{
uint32 itemId = Eluna::CHECKVAL<uint32>(L, 2);
player->DestroyItemCount(itemId, itemCount, true);
}
else
{
bool all = itemCount >= item->GetCount();
player->DestroyItemCount(item, itemCount, true);
if (all)
Eluna::CHECKOBJ<ElunaObject>(L, 2)->Invalidate();
}
return 0;
}
/**
* Removes specified amount of lifetime kills
*
* @param uint32 val : kills to remove
*/
int RemoveLifetimeKills(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 val = Eluna::CHECKVAL<uint32>(L, 2);
uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS);
if (val > currentKills)
val = currentKills;
player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, currentKills - val);
return 0;
}
/**
* Resets cooldown of the specified spell
*
* @param uint32 spellId
* @param bool update = true
*/
int ResetSpellCooldown(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
bool update = Eluna::CHECKVAL<bool>(L, 3, true);
#ifdef TRINITY
player->GetSpellHistory()->ResetCooldown(spellId, update);
#else
player->RemoveSpellCooldown(spellId, update);
#endif
return 0;
}
/**
* Resets cooldown of the specified category
*
* @param uint32 category
* @param bool update = true
*/
int ResetTypeCooldowns(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 category = Eluna::CHECKVAL<uint32>(L, 2);
bool update = Eluna::CHECKVAL<bool>(L, 3, true);
#ifdef TRINITY
player->GetSpellHistory()->ResetCooldowns([category](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itr->first);
return spellInfo && spellInfo->GetCategory() == category;
}, update);
#else
player->RemoveSpellCategoryCooldown(category, update);
#endif
return 0;
}
/**
* Resets all of the [Player]'s cooldowns
*/
int ResetAllCooldowns(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifdef TRINITY
player->GetSpellHistory()->ResetAllCooldowns();
#else
player->RemoveAllSpellCooldown();
#endif
return 0;
}
/**
* Clears a cooldown of the specified spell
*
* @param uint32 spellId : entry of a spell
* @param [Unit] target
*/
int SendClearCooldowns(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
Unit* target = Eluna::CHECKOBJ<Unit>(L, 3);
#ifdef TRINITY
target->GetSpellHistory()->ResetCooldown(spellId, true);
#else
player->SendClearCooldown(spellId, target);
#endif
return 0;
}
/**
* Sends a Broadcast Message to the [Player]
*
* @param string message
*/
int SendBroadcastMessage(Eluna* /*E*/, lua_State* L, Player* player)
{
const char* message = Eluna::CHECKVAL<const char*>(L, 2);
if (std::string(message).length() > 0)
ChatHandler(player->GetSession()).SendSysMessage(message);
return 0;
}
/**
* Sends an Area Trigger Message to the [Player]
*
* @param string message
*/
int SendAreaTriggerMessage(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string msg = Eluna::CHECKVAL<std::string>(L, 2);
if (msg.length() > 0)
player->GetSession()->SendAreaTriggerMessage("%s", msg.c_str());
return 0;
}
/**
* Sends a Notification to the [Player]
*
* @param string message
*/
int SendNotification(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string msg = Eluna::CHECKVAL<std::string>(L, 2);
if (msg.length() > 0)
player->GetSession()->SendNotification("%s", msg.c_str());
return 0;
}
/**
* Sends a [WorldPacket] to the [Player]
*
* @param [WorldPacket] packet
* @param bool selfOnly = true
*/
int SendPacket(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(L, 2);
bool selfOnly = Eluna::CHECKVAL<bool>(L, 3, true);
if (selfOnly)
player->GetSession()->SendPacket(data);
else
player->SendMessageToSet(data, true);
return 0;
}
/**
* Sends addon message to the [Player] receiver
*
* @param string prefix
* @param string message
* @param uint8 channel
* @param [Player] receiver
* @param string fullMsg
*
*/
int SendAddonMessage(Eluna* /*E*/, lua_State* L, Player* player)
{
std::string prefix = Eluna::CHECKVAL<std::string>(L, 2);
std::string message = Eluna::CHECKVAL<std::string>(L, 3);
uint8 channel = Eluna::CHECKVAL<uint8>(L, 4);
Player* receiver = Eluna::CHECKOBJ<Player>(L, 5);
std::string fullmsg = prefix + "\t" + message;
WorldPacket data(SMSG_MESSAGECHAT, 100);
data << uint8(channel);
data << int32(LANG_ADDON);
data << uint64(player->GET_GUID());
#ifndef CLASSIC
data << uint32(0);
data << uint64(receiver->GET_GUID());
#endif
data << uint32(fullmsg.length() + 1);
data << fullmsg;
data << uint8(0);
receiver->GetSession()->SendPacket(&data);
return 0;
}
/**
* Kicks the [Player] from the server
*/
int KickPlayer(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->GetSession()->KickPlayer();
return 0;
}
/**
* Adds or subtracts from the [Player]s money in copper
*
* @param int32 copperAmt : negative to remove, positive to add
*/
int ModifyMoney(Eluna* /*E*/, lua_State* L, Player* player)
{
int32 amt = Eluna::CHECKVAL<int32>(L, 2);
player->ModifyMoney(amt);
return 1;
}
/**
* Teaches the [Player] the [Spell] specified by entry ID
*
* @param uint32 spellId
*/
int LearnSpell(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
#ifdef TRINITY
player->LearnSpell(id, false);
#else
player->learnSpell(id, false);
#endif
return 0;
}
/**
* Learn the [Player] the talent specified by talent_id and talentRank
*
* @param uint32 talent_id
* @param uint32 talentRank
*/
int LearnTalent(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 id = Eluna::CHECKVAL<uint32>(L, 2);
uint32 rank = Eluna::CHECKVAL<uint32>(L, 3);
player->LearnTalent(id, rank);
return 0;
}
/**
* Resurrects the [Player].
*
* @param float healthPercent = 100.0f
* @param bool ressSickness = false
*/
int ResurrectPlayer(Eluna* /*E*/, lua_State* L, Player* player)
{
float percent = Eluna::CHECKVAL<float>(L, 2, 100.0f);
bool sickness = Eluna::CHECKVAL<bool>(L, 3, false);
player->ResurrectPlayer(percent, sickness);
player->SpawnCorpseBones();
return 0;
}
/**
* Adds a new item to the gossip menu shown to the [Player] on next call to [Player:GossipSendMenu].
*
* sender and intid are numbers which are passed directly to the gossip selection handler. Internally they are partly used for the database gossip handling.
* code specifies whether to show a box to insert text to. The player inserted text is passed to the gossip selection handler.
* money specifies an amount of money the player needs to have to click the option. An error message is shown if the player doesn't have enough money.
* Note that the money amount is only checked client side and is not removed from the player either. You will need to check again in your code before taking action.
*
* See also: [Player:GossipSendMenu], [Player:GossipAddQuests], [Player:GossipComplete], [Player:GossipClearMenu]
*
* @param uint32 icon : number that specifies used icon
* @param string msg : label on the gossip item
* @param uint32 sender : number passed to gossip handlers
* @param uint32 intid : number passed to gossip handlers
* @param uint32 code = false : show text input on click if true
* @param string popup = nil : if non empty string, a popup with given text shown on click
* @param uint32 money = 0 : required money in copper
*/
int GossipMenuAddItem(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 _icon = Eluna::CHECKVAL<uint32>(L, 2);
const char* msg = Eluna::CHECKVAL<const char*>(L, 3);
uint32 _sender = Eluna::CHECKVAL<uint32>(L, 4);
uint32 _intid = Eluna::CHECKVAL<uint32>(L, 5);
bool _code = Eluna::CHECKVAL<bool>(L, 6, false);
const char* _promptMsg = Eluna::CHECKVAL<const char*>(L, 7, "");
uint32 _money = Eluna::CHECKVAL<uint32>(L, 8, 0);
#ifndef TRINITY
#ifndef CLASSIC
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _money, _code);
#else
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _code);
#endif
#else
player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, _icon, msg, _sender, _intid, _promptMsg, _money, _code);
#endif
return 0;
}
/**
* Closes the [Player]s currently open Gossip Menu.
*
* See also: [Player:GossipMenuAddItem], [Player:GossipAddQuests], [Player:GossipSendMenu], [Player:GossipClearMenu]
*/
int GossipComplete(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifndef TRINITY
player->PlayerTalkClass->CloseGossip();
#else
player->PlayerTalkClass->SendCloseGossip();
#endif
return 0;
}
/**
* Sends the current gossip items of the player to him as a gossip menu with header text from the given textId.
*
* If sender is a [Player] then menu_id is mandatory, otherwise it is not used for anything.
* menu_id is the ID used to trigger the OnGossipSelect registered for players. See [Global:RegisterPlayerGossipEvent]
*
* See also: [Player:GossipMenuAddItem], [Player:GossipAddQuests], [Player:GossipComplete], [Player:GossipClearMenu]
*
* @proto (npc_text, sender)
* @proto (npc_text, sender, menu_id)
* @param uint32 npc_text : entry ID of a header text in npc_text database table, common default is 100
* @param [Object] sender : object acting as the source of the sent gossip menu
* @param uint32 menu_id : if sender is a [Player] then menu_id is mandatory
*/
int GossipSendMenu(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 npc_text = Eluna::CHECKVAL<uint32>(L, 2);
Object* sender = Eluna::CHECKOBJ<Object>(L, 3);
if (sender->GetTypeId() == TYPEID_PLAYER)
{
uint32 menu_id = Eluna::CHECKVAL<uint32>(L, 4);
player->PlayerTalkClass->GetGossipMenu().SetMenuId(menu_id);
}
player->PlayerTalkClass->SendGossipMenu(npc_text, sender->GET_GUID());
return 0;
}
/**
* Clears the [Player]s current gossip item list.
*
* See also: [Player:GossipMenuAddItem], [Player:GossipSendMenu], [Player:GossipAddQuests], [Player:GossipComplete]
*
* Note: This is needed when you show a gossip menu without using gossip hello or select hooks which do this automatically.
* Usually this is needed when using [Player] is the sender of a Gossip Menu.
*/
int GossipClearMenu(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->PlayerTalkClass->ClearMenus();
return 0;
}
/**
* Attempts to start the taxi/flying to the given pathID
*
* @param uint32 pathId : pathId from DBC or [Global:AddTaxiPath]
*/
int StartTaxi(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 pathId = Eluna::CHECKVAL<uint32>(L, 2);
player->ActivateTaxiPathTo(pathId);
return 0;
}
/**
* Sends POI to the location on your map
*
* @param float x
* @param float y
* @param uint32 icon : map icon to show
* @param uint32 flags
* @param uint32 data
* @param string iconText
*/
int GossipSendPOI(Eluna* /*E*/, lua_State* L, Player* player)
{
float x = Eluna::CHECKVAL<float>(L, 2);
float y = Eluna::CHECKVAL<float>(L, 3);
uint32 icon = Eluna::CHECKVAL<uint32>(L, 4);
uint32 flags = Eluna::CHECKVAL<uint32>(L, 5);
uint32 data = Eluna::CHECKVAL<uint32>(L, 6);
std::string iconText = Eluna::CHECKVAL<std::string>(L, 7);
WorldPacket packet(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 10);
packet << flags;
packet << x;
packet << y;
packet << icon;
packet << data;
packet << iconText;
player->GetSession()->SendPacket(&packet);
return 0;
}
/**
* Adds the gossip items to the [Player]'s gossip for the quests the given [WorldObject] can offer to the player.
*
* @param [WorldObject] source : a questgiver with quests
*/
int GossipAddQuests(Eluna* /*E*/, lua_State* L, Player* player)
{
WorldObject* source = Eluna::CHECKOBJ<WorldObject>(L, 2);
if (source->GetTypeId() == TYPEID_UNIT)
{
if (source->GetUInt32Value(UNIT_NPC_FLAGS) & UNIT_NPC_FLAG_QUESTGIVER)
player->PrepareQuestMenu(source->GET_GUID());
}
else if (source->GetTypeId() == TYPEID_GAMEOBJECT)
{
if (source->ToGameObject()->GetGoType() == GAMEOBJECT_TYPE_QUESTGIVER)
player->PrepareQuestMenu(source->GET_GUID());
}
return 0;
}
/**
* Shows a quest accepting window to the [Player] for the given quest.
*
* @param uint32 questId : entry of a quest
* @param bool activateAccept = true : auto finish the quest
*/
int SendQuestTemplate(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
bool activateAccept = Eluna::CHECKVAL<bool>(L, 3, true);
Quest const* quest = eObjectMgr->GetQuestTemplate(questId);
if (!quest)
return 0;
player->PlayerTalkClass->SendQuestGiverQuestDetails(quest, player->GET_GUID(), activateAccept);
return 0;
}
/**
* Converts [Player]'s corpse to bones
*/
int SpawnBones(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
player->SpawnCorpseBones();
return 0;
}
/**
* Loots [Player]'s bones for insignia
*
* @param [Player] looter
*/
int RemovedInsignia(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* looter = Eluna::CHECKOBJ<Player>(L, 2);
player->RemovedInsignia(looter);
return 0;
}
/**
* Makes the [Player] invite another player to a group.
*
* @param [Player] invited : player to invite to group
* @return bool success : true if the player was invited to a group
*/
int GroupInvite(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* invited = Eluna::CHECKOBJ<Player>(L, 2);
if (invited->GetGroup() || invited->GetGroupInvite())
{
Eluna::Push(L, false);
return 1;
}
// Get correct existing group if any
Group* group = player->GetGroup();
if (group && group->isBGGroup())
group = player->GetOriginalGroup();
bool success = false;
// Try invite if group found
if (group)
success = !group->IsFull() && group->AddInvite(invited);
else
{
// Create new group if one not found
group = new Group;
success = group->AddLeaderInvite(player) && group->AddInvite(invited);
if (!success)
delete group;
}
if (success)
{
#if defined(CLASSIC) || defined(TBC)
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
data << player->GetName();
invited->GetSession()->SendPacket(&data);
#else
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
data << uint8(1); // invited/already in group flag
data << player->GetName(); // max len 48
data << uint32(0); // unk
data << uint8(0); // count
data << uint32(0); // unk
invited->GetSession()->SendPacket(&data);
#endif
}
Eluna::Push(L, success);
return 1;
}
/**
* Creates a new [Group] with the creator [Player] as leader.
*
* @param [Player] invited : player to add to group
* @return [Group] createdGroup : the created group or nil
*/
int GroupCreate(Eluna* /*E*/, lua_State* L, Player* player)
{
Player* invited = Eluna::CHECKOBJ<Player>(L, 2);
if (player->GetGroup() || invited->GetGroup())
return 0;
if (Group* invitedgroup = player->GetGroupInvite())
player->UninviteFromGroup();
if (Group* invitedgroup = invited->GetGroupInvite())
invited->UninviteFromGroup();
// Try create new group
Group* group = new Group;
if (!group->AddLeaderInvite(player))
{
delete group;
return 0;
}
// Forming a new group, create it
if (!group->IsCreated())
{
group->RemoveInvite(player);
#ifdef TRINITY
group->Create(player);
sGroupMgr->AddGroup(group);
#else
if (!group->Create(group->GetLeaderGuid(), group->GetLeaderName()))
return 0;
sObjectMgr.AddGroup(group);
#endif
}
#ifdef TRINITY
if (!group->AddMember(invited))
return 0;
group->BroadcastGroupUpdate();
#else
if (!group->AddMember(invited->GetObjectGuid(), invited->GetName()))
return 0;
#endif
Eluna::Push(L, group);
return 1;
}
/**
* Starts a cinematic for the [Player]
*
* @param uint32 CinematicSequenceId : entry of a cinematic
*/
int SendCinematicStart(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 CinematicSequenceId = Eluna::CHECKVAL<uint32>(L, 2);
player->SendCinematicStart(CinematicSequenceId);
return 0;
}
#if !defined(CLASSIC) && !defined(TBC)
/**
* Starts a movie for the [Player]
*
* @param uint32 MovieId : entry of a movie
*/
int SendMovieStart(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 MovieId = Eluna::CHECKVAL<uint32>(L, 2);
player->SendMovieStart(MovieId);
return 0;
}
#endif
/*int BindToInstance(Eluna* E, lua_State* L, Player* player)
{
player->BindToInstance();
return 0;
}*/
/*int AddTalent(Eluna* E, lua_State* L, Player* player)
{
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
uint8 spec = Eluna::CHECKVAL<uint8>(L, 3);
bool learning = Eluna::CHECKVAL<bool>(L, 4, true);
if (spec >= MAX_TALENT_SPECS)
Eluna::Push(L, false);
else
Eluna::Push(L, player->AddTalent(spellId, spec, learning));
return 1;
}*/
/*int GainSpellComboPoints(Eluna* E, lua_State* L, Player* player)
{
int8 count = Eluna::CHECKVAL<int8>(L, 2);
player->GainSpellComboPoints(count);
return 0;
}*/
/*int KillGOCredit(Eluna* E, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
uint64 guid = Eluna::CHECKVAL<uint64>(L, 3);
player->KillCreditGO(entry, guid);
return 0;
}*/
/*int KilledPlayerCredit(Eluna* E, lua_State* L, Player* player)
{
player->KilledPlayerCredit();
return 0;
}*/
/*int RemoveRewardedQuest(Eluna* E, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
player->RemoveRewardedQuest(entry);
return 0;
}*/
/*int RemoveActiveQuest(Eluna* E, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
player->RemoveActiveQuest(entry);
return 0;
}*/
/*int SummonPet(Eluna* E, lua_State* L, Player* player)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2);
float x = Eluna::CHECKVAL<float>(L, 3);
float y = Eluna::CHECKVAL<float>(L, 4);
float z = Eluna::CHECKVAL<float>(L, 5);
float o = Eluna::CHECKVAL<float>(L, 6);
uint32 petType = Eluna::CHECKVAL<uint32>(L, 7);
uint32 despwtime = Eluna::CHECKVAL<uint32>(L, 8);
if (petType >= MAX_PET_TYPE)
return 0;
player->SummonPet(entry, x, y, z, o, (PetType)petType, despwtime);
return 0;
}*/
/*int RemovePet(Eluna* E, lua_State* L, Player* player)
{
int mode = Eluna::CHECKVAL<int>(L, 2, PET_SAVE_AS_DELETED);
bool returnreagent = Eluna::CHECKVAL<bool>(L, 2, false);
if (!player->GetPet())
return 0;
player->RemovePet(player->GetPet(), (PetSaveMode)mode, returnreagent);
return 0;
}*/
};
#endif