Skip to content

Commit

Permalink
Add Item Template methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Niam5 committed Feb 25, 2024
1 parent 3ac6d7e commit 82dc5aa
Show file tree
Hide file tree
Showing 7 changed files with 883 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CMangos/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ namespace LuaGlobalFunctions
return 1;
}

/**
* Returns the [ItemTemplate] for this [Item].
*
* @param uint32 entry : entry ID of the [Item]
* @return ItemTemplate : ItemTemplate of the [Item]
*/

int GetItemTemplateEntry(Eluna* E)
{
uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 1);
E->Push(eObjectMgr->GetItemPrototype(entry));
return 1;
}

/**
* Builds a [GameObject]'s GUID.
*
Expand Down Expand Up @@ -3238,6 +3252,7 @@ namespace LuaGlobalFunctions
{ "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount },
{ "GetPlayerGUID", &LuaGlobalFunctions::GetPlayerGUID },
{ "GetItemGUID", &LuaGlobalFunctions::GetItemGUID },
{ "GetItemTemplate", &LuaGlobalFunctions::GetItemTemplateEntry },
{ "GetObjectGUID", &LuaGlobalFunctions::GetObjectGUID },
{ "GetUnitGUID", &LuaGlobalFunctions::GetUnitGUID },
{ "GetGUIDLow", &LuaGlobalFunctions::GetGUIDLow },
Expand Down
12 changes: 12 additions & 0 deletions CMangos/ItemMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,17 @@ namespace LuaItem
return 1;
}

/**
* Returns the [ItemTemplate] for this [Item].
*
* @return [ItemTemplate] itemTemplate
*/
int GetItemTemplateEntry(Eluna* E, Item* item)
{
E->Push(item->GetProto());
return 1;
}

/**
* Sets the [Player] specified as the owner of the [Item]
*
Expand Down Expand Up @@ -753,6 +764,7 @@ namespace LuaItem
{ "GetRandomProperty", &LuaItem::GetRandomProperty },
{ "GetItemSet", &LuaItem::GetItemSet },
{ "GetBagSize", &LuaItem::GetBagSize },
{ "GetItemTemplate", &LuaItem::GetItemTemplateEntry },
#if defined(TBC) || defined(WOTLK)
{ "GetRandomSuffix", &LuaItem::GetRandomSuffix },
#else
Expand Down
213 changes: 213 additions & 0 deletions CMangos/ItemTemplateMethods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/*
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/

#ifndef ITEMTEMPLATEMETHODS_H
#define ITEMTEMPLATEMETHODS_H

/***
* Inherits all methods from: [Object]
*/
namespace LuaItemTemplate
{
/**
* Returns the [ItemTemplate]'s ID.
*
* @return uint32 itemId
*/
int GetItemId(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->ItemId);
return 1;
}

/**
* Returns the [ItemTemplate]'s class.
*
* @return uint32 class
*/
int GetClass(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->Class);
return 1;
}

/**
* Returns the [ItemTemplate]'s subclass.
*
* @return uint32 subClass
*/
int GetSubClass(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->SubClass);
return 1;
}

/**
* Returns the [ItemTemplate]'s name.
*
* @return string name
*/
int GetName(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->Name1);
return 1;
}

/**
* Returns the [ItemTemplate]'s display ID.
*
* @return uint32 displayId
*/
int GetDisplayId(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->DisplayInfoID);
return 1;
}

/**
* Returns the [ItemTemplate]'s quality.
*
* @return uint32 quality
*/
int GetQuality(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->Quality);
return 1;
}

/**
* Returns the [ItemTemplate]'s flags.
*
* @return uint32 flags
*/
int GetFlags(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->Flags);
return 1;
}

/**
* Returns the [ItemTemplate]'s extra flags.
*
* @return uint32 flags
*/
int GetExtraFlags(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->Flags2);
return 1;
}

/**
* Returns the [ItemTemplate]'s default purchase count.
*
* @return uint32 buyCount
*/
int GetBuyCount(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->BuyCount);
return 1;
}

/**
* Returns the [ItemTemplate]'s purchase price.
*
* @return int32 buyPrice
*/
int GetBuyPrice(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->BuyPrice);
return 1;
}

/**
* Returns the [ItemTemplate]'s sell price.
*
* @return uint32 sellPrice
*/
int GetSellPrice(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->SellPrice);
return 1;
}

/**
* Returns the [ItemTemplate]'s inventory type.
*
* @return uint32 inventoryType
*/
int GetInventoryType(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->InventoryType);
return 1;
}

/**
* Returns the [Player] classes allowed to use this [ItemTemplate].
*
* @return uint32 allowableClass
*/
int GetAllowableClass(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->AllowableClass);
return 1;
}

/**
* Returns the [Player] races allowed to use this [ItemTemplate].
*
* @return uint32 allowableRace
*/
int GetAllowableRace(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->AllowableRace);
return 1;
}

/**
* Returns the [ItemTemplate]'s item level.
*
* @return uint32 itemLevel
*/
int GetItemLevel(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->ItemLevel);
return 1;
}

/**
* Returns the minimum level required to use this [ItemTemplate].
*
* @return uint32 requiredLevel
*/
int GetRequiredLevel(Eluna* E, ItemTemplate* itemTemplate)
{
E->Push(itemTemplate->RequiredLevel);
return 1;
}

ElunaRegister<ItemTemplate> ItemTemplateMethods[] =
{
// Getters
{ "GetItemId", &LuaItemTemplate::GetItemId },
{ "GetClass", &LuaItemTemplate::GetClass },
{ "GetSubClass", &LuaItemTemplate::GetSubClass },
{ "GetName", &LuaItemTemplate::GetName },
{ "GetDisplayId", &LuaItemTemplate::GetDisplayId },
{ "GetQuality", &LuaItemTemplate::GetQuality },
{ "GetFlags", &LuaItemTemplate::GetFlags },
{ "GetExtraFlags", &LuaItemTemplate::GetExtraFlags },
{ "GetBuyCount", &LuaItemTemplate::GetBuyCount },
{ "GetBuyPrice", &LuaItemTemplate::GetBuyPrice },
{ "GetSellPrice", &LuaItemTemplate::GetSellPrice },
{ "GetInventoryType", &LuaItemTemplate::GetInventoryType },
{ "GetAllowableClass", &LuaItemTemplate::GetAllowableClass },
{ "GetItemLevel", &LuaItemTemplate::GetItemLevel },
{ "GetRequiredLevel", &LuaItemTemplate::GetRequiredLevel },

{ NULL, NULL, METHOD_REG_NONE }
};
};
#endif
4 changes: 4 additions & 0 deletions LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern "C"
#include "ElunaQueryMethods.h"
#include "AuraMethods.h"
#include "ItemMethods.h"
#include "ItemTemplateMethods.h"
#include "WorldPacketMethods.h"
#include "SpellMethods.h"
#include "QuestMethods.h"
Expand Down Expand Up @@ -139,6 +140,9 @@ void RegisterFunctions(Eluna* E)
ElunaTemplate<Item>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Item>::SetMethods(E, LuaItem::ItemMethods);

ElunaTemplate<ItemTemplate>::Register(E, "ItemTemplate");
ElunaTemplate<ItemTemplate>::SetMethods(E, LuaItemTemplate::ItemTemplateMethods);

#ifndef CLASSIC
#ifndef TBC
ElunaTemplate<Vehicle>::Register(E, "Vehicle");
Expand Down
Loading

0 comments on commit 82dc5aa

Please sign in to comment.