player functions for direct item bag manipulation

This commit is contained in:
Zithia Satazaki 2023-10-30 01:05:18 -04:00
parent fa6a770cfc
commit 943729a20e

View File

@ -201,6 +201,32 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
}
});
callbacks.registerCallback("itemBagSize", [player](String const& bag) {
auto inventory = player->inventory();
auto b = inventory->bagContents(bag);
return b->size();
});
callbacks.registerCallback("itemAllowedInBag", [player](String const& bag, Json const& item) {
auto inventory = player->inventory();
auto itemDatabase = Root::singleton().itemDatabase();
return inventory->itemAllowedInBag(itemDatabase->item(ItemDescriptor(item)), bag);
});
callbacks.registerCallback("itemBagItem", [player](String const& bag, int slot) -> Json {
auto inventory = player->inventory();
auto b = inventory->bagContents(bag);
//if (b.get() == nullptr) return {};
return itemSafeDescriptor(b->at(slot - 1)).toJson();
});
callbacks.registerCallback("setItemBagItem", [player](String const& bag, int slot, Json const& item) {
auto inventory = player->inventory();
auto itemDatabase = Root::singleton().itemDatabase();
auto b = const_pointer_cast<ItemBag>(inventory->bagContents(bag)); // bit of a Naughty Access Cheat here, but
b->setItem(slot - 1, itemDatabase->item(ItemDescriptor(item)));
});
callbacks.registerCallback("setDamageTeam", [player](String const& typeName, Maybe<uint16_t> teamNumber) {
player->setTeam(EntityDamageTeam(TeamTypeNames.getLeft(typeName), teamNumber.value(0)));
});