feat(Pet): Add Pet Object and Methods (#288)

This commit is contained in:
iThorgrim
2025-08-29 03:59:04 +02:00
committed by GitHub
parent de84ed1369
commit 84d1c0cceb
3 changed files with 1029 additions and 27 deletions

View File

@@ -2072,18 +2072,6 @@ namespace LuaPlayer
return 0;
}*/
/**
* Resets the [Player]s pets talent points
*/
int ResetPetTalents(lua_State* /*L*/, Player* player)
{
Pet* pet = player->GetPet();
Pet::resetTalentsForAllPetsOf(player, pet);
if (pet)
player->SendTalentsInfoData(true);
return 0;
}
/**
* Reset the [Player]s completed achievements
*/
@@ -4040,6 +4028,17 @@ namespace LuaPlayer
return 0;
}
/**
* Returns the [Player]'s current [Pet], if any.
*
* @return [Pet] pet : the player's pet, or `nil` if no pet
*/
int GetPet(lua_State* L, Player* player)
{
Eluna::Push(L, player->GetPet());
return 1;
}
/**
* Returns `true` if the [Player] is at maximum level, `false` otherwise.
*
@@ -4051,6 +4050,35 @@ namespace LuaPlayer
return 1;
}
/**
* Summons a [Pet] at the specified location.
*
* @param uint32 entry : the creature entry ID to summon
* @param float x : X coordinate
* @param float y : Y coordinate
* @param float z : Z coordinate
* @param float ang : orientation angle
* @param [PetType] petType : the type of pet to summon
* @param uint32 duration = 0 : duration in milliseconds, 0 for permanent
* @param uint32 healthPct = 0 : initial health percentage
* @return [Pet] pet : the summoned pet, or `nil` if failed
*/
int SummonPet(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 ang = Eluna::CHECKVAL<float>(L, 6);
uint32 petType = Eluna::CHECKVAL<uint32>(L, 7);
uint32 duration = Eluna::CHECKVAL<uint32>(L, 8, 0);
uint32 healthPct = Eluna::CHECKVAL<uint32>(L, 9, 0);
Pet* pet = player->SummonPet(entry, x, y, z, ang, static_cast<PetType>(petType), Milliseconds(duration), healthPct);
Eluna::Push(L, pet);
return 1;
}
/**
* Returns the average item level of the [Player]'s equipment.
*
@@ -4062,6 +4090,36 @@ namespace LuaPlayer
return 1;
}
/**
* Creates a tamed [Pet] from a [Creature] or creature entry.
*
* Can be called with either:
* - `player:CreatePet(creatureEntry)` - creates pet from entry ID
* - `player:CreatePet(creature, spellID)` - tames existing creature
*
* @param uint32 creatureEntry : creature entry ID (first form)
* @param [Creature] creature : target creature to tame (second form)
* @param uint32 spellID = 0 : spell used for taming (second form)
* @return [Pet] pet : the created pet, or `nil` if failed
*/
int CreatePet(lua_State* L, Player* player)
{
if (lua_gettop(L) == 2)
{
uint32 creatureEntry = Eluna::CHECKVAL<uint32>(L, 2);
Pet* pet = player->CreatePet(creatureEntry);
Eluna::Push(L, pet);
}
else
{
Creature* creatureTarget = Eluna::CHECKOBJ<Creature>(L, 2);
uint32 spellID = Eluna::CHECKVAL<uint32>(L, 3, 0);
Pet* pet = player->CreatePet(creatureTarget, spellID);
Eluna::Push(L, pet);
}
return 1;
}
/**
* Returns `true` if the [Player] has completed the daily quest, `false` otherwise.
*
@@ -4075,6 +4133,17 @@ namespace LuaPlayer
return 1;
}
/**
* Temporarily unsummons the [Player]'s current [Pet].
*
* The pet can be resummoned later. Used during teleportation, mounting, etc.
*/
int UnsummonPetTemporarily(lua_State* /*L*/, Player* player)
{
player->UnsummonPetTemporaryIfAny();
return 0;
}
/**
* Sets the specified player flag on the [Player].
*
@@ -4087,6 +4156,22 @@ namespace LuaPlayer
return 0;
}
/**
* Removes the specified [Pet] from the [Player].
*
* @param [Pet] pet : the pet to remove
* @param [PetSaveMode] mode : how to handle pet removal
* @param bool returnReagent = false : if `true`, returns reagents used to summon
*/
int RemovePet(lua_State* L, Player* player)
{
Pet* pet = Eluna::CHECKOBJ<Pet>(L, 2);
uint32 mode = Eluna::CHECKVAL<uint32>(L, 3);
bool returnReagent = Eluna::CHECKVAL<bool>(L, 4, false);
player->RemovePet(pet, static_cast<PetSaveMode>(mode), returnReagent);
return 1;
}
/**
* Removes the specified player flag from the [Player].
*
@@ -4099,6 +4184,17 @@ namespace LuaPlayer
return 0;
}
/**
* Returns `true` if the [Player] can resurrect their [Pet] and returns `false` otherwise.
*
* @return bool canResurrect
*/
int CanPetResurrect(lua_State* L, Player* player)
{
Eluna::Push(L, player->CanPetResurrect());
return 1;
}
/**
* Returns a random number between the specified minimum and maximum values.
*
@@ -4184,6 +4280,17 @@ namespace LuaPlayer
return 1;
}
/**
* Returns `true` if the [Player] has a [Pet] (active or stored) and returns `false` otherwise.
*
* @return bool hasExistingPet
*/
int IsExistPet(lua_State* L, Player* player)
{
Eluna::Push(L, player->IsExistPet());
return 1;
}
/**
* Returns `true` if the [Player] can take the specified quest, `false` otherwise.
*
@@ -4199,6 +4306,16 @@ namespace LuaPlayer
return 1;
}
/**
* Resets the [Player]'s pet talents.
*
*/
int ResetPetTalents(lua_State* /*L*/, Player* player)
{
player->ResetPetTalents();
return 0;
}
/**
* Returns `true` if the [Player] can add the specified quest, `false` otherwise.
*
@@ -4290,6 +4407,22 @@ namespace LuaPlayer
return 0;
}
/**
* Learns a pet talent for the specified [Pet] of the [Player].
*
* @param ObjectGuid petGuid : GUID of the pet to learn the talent for
* @param uint32 talentId : ID of the talent to learn
* @param uint32 talentRank : rank of the talent to learn
*/
int LearnPetTalent(lua_State* L, Player* player)
{
ObjectGuid petGuid = Eluna::CHECKVAL<ObjectGuid>(L, 2);
uint32 talentId = Eluna::CHECKVAL<uint32>(L, 3);
uint32 talentRank = Eluna::CHECKVAL<uint32>(L, 4);
player->LearnPetTalent(petGuid, talentId, talentRank);
return 0;
}
/**
* Returns `true` if the [Player] has a title by bit index, `false` otherwise.
*
@@ -4341,6 +4474,17 @@ namespace LuaPlayer
return 0;
}
/**
* Returns `true` if the [Player] can tame exotic pets, and `false` otherwise.
*
* @return bool canTameExoticPets : `true` if the player can tame exotic pets, `false` otherwise
*/
int CanTameExoticPets(lua_State* L, Player* player)
{
Eluna::Push(L, player->CanTameExoticPets());
return 1;
}
/**
* Returns the [Player]'s weapon proficiency flags.
*
@@ -4352,6 +4496,17 @@ namespace LuaPlayer
return 1;
}
/**
* Returns the temporary unsummoned pet number for the [Player].
*
* @return uint32 petNumber : the temporary unsummoned pet number
*/
int GetTemporaryUnsummonedPetNumber(lua_State* L, Player* player)
{
Eluna::Push(L, player->GetTemporaryUnsummonedPetNumber());
return 1;
}
/**
* Returns the [Player]'s armor proficiency flags.
*
@@ -4363,6 +4518,18 @@ namespace LuaPlayer
return 1;
}
/**
* Sets the temporary unsummoned pet number for the [Player].
*
* @param uint32 petNumber : the pet number to set
*/
int SetTemporaryUnsummonedPetNumber(lua_State* L, Player* player)
{
uint32 petNumber = Eluna::CHECKVAL<uint32>(L, 2);
player->SetTemporaryUnsummonedPetNumber(petNumber);
return 0;
}
/**
* Adds weapon proficiency to the [Player].
*
@@ -4375,6 +4542,16 @@ namespace LuaPlayer
return 0;
}
/**
* Resummons the [Player]'s pet if it was temporarily unsummoned.
*
*/
int ResummonPetTemporaryUnSummonedIfAny(lua_State* /*L*/, Player* player)
{
player->ResummonPetTemporaryUnSummonedIfAny();
return 0;
}
/**
* Adds armor proficiency to the [Player].
*
@@ -4387,6 +4564,18 @@ namespace LuaPlayer
return 0;
}
/**
* Returns `true` if the [Player] needs to temporarily unsummon their [Pet], and `false` otherwise.
*
*
* @return bool isPetNeedBeTemporaryUnsummoned : `true` if the pet needs to be temporarily unsummoned, `false` otherwise
*/
int IsPetNeedBeTemporaryUnsummoned(lua_State* L, Player* player)
{
Eluna::Push(L, player->IsPetNeedBeTemporaryUnsummoned());
return 1;
}
/**
* Sets the [Player]'s ammo item.
*
@@ -4419,6 +4608,19 @@ namespace LuaPlayer
return 1;
}
/**
* Returns `true` if the [Player] can resummon a [Pet] with the specified spell ID, and `false` otherwise.
*
* @param uint32 spellId : the spell ID to check
* @return bool canResummon : `true` if the player can resummon the pet, `false` otherwise
*/
int CanResummonPet(lua_State* L, Player* player)
{
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
Eluna::Push(L, player->CanResummonPet(spellId));
return 1;
}
/**
* Returns the [Player]'s shield item.
*
@@ -4430,6 +4632,17 @@ namespace LuaPlayer
return 1;
}
/**
* Returns the last pet number for the [Player].
*
* @return uint32 petNumber : the last pet number
*/
int GetLastPetNumber(lua_State* L, Player* player)
{
Eluna::Push(L, player->GetLastPetNumber());
return 1;
}
/**
* Returns `true` if the [Player] can teleport, `false` otherwise.
*
@@ -4441,6 +4654,18 @@ namespace LuaPlayer
return 1;
}
/**
* Sets the last pet number for the [Player].
*
* @param uint32 petNumber : the pet number to set
*/
int SetLastPetNumber(lua_State* L, Player* player)
{
uint32 petNumber = Eluna::CHECKVAL<uint32>(L, 2);
player->SetLastPetNumber(petNumber);
return 0;
}
/**
* Sets whether the [Player] can teleport.
*
@@ -4453,6 +4678,17 @@ namespace LuaPlayer
return 0;
}
/**
* Returns the spell ID of the [Player]'s last [Pet] summoning spell.
*
* @return uint32 petSpell : the pet spell ID
*/
int GetLastPetSpell(lua_State* L, Player* player)
{
Eluna::Push(L, player->GetLastPetSpell());
return 1;
}
/**
* Returns the [Player]'s runes state for Death Knights.
*
@@ -4464,6 +4700,18 @@ namespace LuaPlayer
return 1;
}
/**
* Sets the spell ID of the [Player]'s last [Pet] summoning spell.
*
* @param uint32 petSpell : the pet spell ID to set
*/
int SetLastPetSpell(lua_State* L, Player* player)
{
uint32 petSpell = Eluna::CHECKVAL<uint32>(L, 2);
player->SetLastPetSpell(petSpell);
return 0;
}
/**
* Returns `true` if the [Player] is a spectator, `false` otherwise.
*
@@ -4487,6 +4735,17 @@ namespace LuaPlayer
return 0;
}
/**
* Returns `true` if the [Player] can see Death Knight [Pet]s, and `false` otherwise.
*
* @return bool canSeeDKPet
*/
int CanSeeDKPet(lua_State* L, Player* player)
{
Eluna::Push(L, player->CanSeeDKPet());
return 1;
}
/**
* Returns the [Player]'s current viewpoint target.
*
@@ -4498,6 +4757,18 @@ namespace LuaPlayer
return 1;
}
/**
* Sets whether the [Player] can see Death Knight [Pet]s.
*
* @param bool show : `true` to show DK pets, `false` to hide them
*/
int SetShowDKPet(lua_State* L, Player* player)
{
bool show = Eluna::CHECKVAL<bool>(L, 2);
player->SetShowDKPet(show);
return 0;
}
/**
* Sets the [Player]'s viewpoint to the specified target.
*
@@ -4607,21 +4878,6 @@ namespace LuaPlayer
Eluna::Push(L, player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot + BANK_SLOT_ITEM_START));
return 1;
}
// /**
// * Returns `true` if the [Player] has a spell mod for the specified spell and operation, `false` otherwise.
// *
// * @param uint32 spellId : the spell ID to check
// * @param uint32 op : the spell mod operation type
// * @return bool hasSpellMod
// */
// int HasSpellMod(lua_State* L, Player* player)
// {
// uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2);
// uint32 op = Eluna::CHECKVAL<uint32>(L, 3);
// Eluna::Push(L, player->HasSpellMod(spellId, SpellModOp(op)));
// return 1;
// }
};
#endif