mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-19 13:28:25 +00:00
[Quest API] Add client->SummonBaggedItems(bag_item_id, bag_items_ref) to Perl/Lua.
Alternative apis using arrays of hash items for EQEmu/Server#1575 Perl usage: ```pl # create as an array, pass as reference my @bag_items = ( { item_id => 1001, charges => 1 }, { item_id => 1002, charges => 1 }, { item_id => 10037, charges => 10 }, ); $client->SummonBaggedItems(17403, \@bag_items); # create directly as an array reference my $bag_items = [ { item_id => 1001, charges => 1 }, { item_id => 1002, charges => 1 }, { item_id => 10037, charges => 10 }, ]; $client->SummonBaggedItems(17403, $bag_items); ``` Lua Usage: ```lua local bag_items = { { item_id = 1001, charges = 1 }, { item_id = 1002, charges = 1 }, { item_id = 10037, charges = 10 } } e.other:SummonBaggedItems(17403, bag_items);
This commit is contained in:
@@ -5712,6 +5712,57 @@ XS(XS_Client_UntrainDiscBySpellID) {
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
XS(XS_Client_SummonBaggedItems); /* prototype to pass -Wmissing-prototypes */
|
||||
XS(XS_Client_SummonBaggedItems) {
|
||||
dXSARGS;
|
||||
if (items != 3) {
|
||||
Perl_croak(aTHX_ "Usage: Client::SummonBaggedItems(THIS, uint32 bag_item_id, ARRAYREF bag_items_array)"); // @categories Inventory and Items, Script Utility
|
||||
}
|
||||
|
||||
Client* THIS;
|
||||
VALIDATE_THIS_IS_CLIENT;
|
||||
|
||||
uint32 bag_item_id = (uint32) SvUV(ST(1));
|
||||
|
||||
// verify we're receiving a reference to an array type
|
||||
SV* bag_items_avref = ST(2);
|
||||
if (!bag_items_avref || !SvROK(bag_items_avref) || SvTYPE(SvRV(bag_items_avref)) != SVt_PVAV)
|
||||
{
|
||||
Perl_croak(aTHX_ "Client::SummonBaggedItems second argument is not a reference to an array");
|
||||
}
|
||||
|
||||
// dereference into the array
|
||||
AV* bag_items_av = (AV*)SvRV(bag_items_avref);
|
||||
|
||||
std::vector<ServerLootItem_Struct> bagged_items;
|
||||
|
||||
auto count = av_len(bag_items_av) + 1;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
SV** element = av_fetch(bag_items_av, i, 0);
|
||||
|
||||
// verify array element is a hash reference containing item details
|
||||
if (element && SvROK(*element) && SvTYPE(SvRV(*element)) == SVt_PVHV)
|
||||
{
|
||||
HV* hash = (HV*)SvRV(*element); // dereference
|
||||
|
||||
SV** item_id_ptr = hv_fetchs(hash, "item_id", false);
|
||||
SV** item_charges_ptr = hv_fetchs(hash, "charges", false);
|
||||
if (item_id_ptr && item_charges_ptr)
|
||||
{
|
||||
ServerLootItem_Struct item{};
|
||||
item.item_id = static_cast<uint32>(SvUV(*item_id_ptr));
|
||||
item.charges = static_cast<int16>(SvIV(*item_charges_ptr));
|
||||
bagged_items.emplace_back(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
THIS->SummonBaggedItems(bag_item_id, bagged_items);
|
||||
|
||||
XSRETURN_EMPTY;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
@@ -6001,6 +6052,7 @@ XS(boot_Client) {
|
||||
newXSproto(strcpy(buf, "Sit"), XS_Client_Sit, file, "$");
|
||||
newXSproto(strcpy(buf, "SlotConvert2"), XS_Client_SlotConvert2, file, "$$");
|
||||
newXSproto(strcpy(buf, "Stand"), XS_Client_Stand, file, "$");
|
||||
newXSproto(strcpy(buf, "SummonBaggedItems"), XS_Client_SummonBaggedItems, file, "$$$");
|
||||
newXSproto(strcpy(buf, "SummonItem"), XS_Client_SummonItem, file, "$$;$$$$$$$$");
|
||||
newXSproto(strcpy(buf, "TakeMoneyFromPP"), XS_Client_TakeMoneyFromPP, file, "$$;$");
|
||||
newXSproto(strcpy(buf, "TGB"), XS_Client_TGB, file, "$");
|
||||
|
||||
Reference in New Issue
Block a user