[Quest API] Add Parcel Sending to Perl/Lua (#4287)

This commit is contained in:
Alex King
2024-05-04 18:11:59 -04:00
committed by GitHub
parent 46f3e50b5c
commit c4cda66c3b
3 changed files with 174 additions and 0 deletions
+73
View File
@@ -5504,6 +5504,78 @@ std::string lua_get_zone_short_name_by_long_name(std::string zone_long_name) {
return zone_store.GetZoneShortNameByLongName(zone_long_name);
}
bool lua_send_parcel(luabind::object lua_table)
{
if (luabind::type(lua_table) != LUA_TTABLE) {
return false;
}
if (
(luabind::type(lua_table["name"]) == LUA_TNIL && luabind::type(lua_table["character_id"]) == LUA_TNIL) ||
luabind::type(lua_table["item_id"]) == LUA_TNIL ||
luabind::type(lua_table["quantity"]) == LUA_TNIL
) {
return false;
}
std::string name = luabind::type(lua_table["name"]) != LUA_TNIL ? luabind::object_cast<std::string>(lua_table["name"]) : "";
uint32 character_id = luabind::type(lua_table["character_id"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["character_id"]) : 0;
if (character_id) {
const std::string& character_name = database.GetCharName(character_id);
if (character_name.empty()) {
return false;
}
name = character_name;
} else {
auto v = CharacterParcelsRepository::GetParcelCountAndCharacterName(database, name);
if (v.at(0).character_name.empty()) {
return false;
}
character_id = v.at(0).char_id;
}
if (!character_id) {
return false;
}
const int next_parcel_slot = CharacterParcelsRepository::GetNextFreeParcelSlot(database, character_id, RuleI(Parcel, ParcelMaxItems));
if (next_parcel_slot == INVALID_INDEX) {
return false;
}
const uint32 item_id = luabind::object_cast<uint32>(lua_table["item_id"]);
const int16 quantity = luabind::object_cast<int16>(lua_table["quantity"]);
const uint32 augment_one = luabind::type(lua_table["augment_one"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["augment_one"]) : 0;
const uint32 augment_two = luabind::type(lua_table["augment_two"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["augment_two"]) : 0;
const uint32 augment_three = luabind::type(lua_table["augment_three"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["augment_three"]) : 0;
const uint32 augment_four = luabind::type(lua_table["augment_four"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["augment_four"]) : 0;
const uint32 augment_five = luabind::type(lua_table["augment_five"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["augment_five"]) : 0;
const uint32 augment_six = luabind::type(lua_table["augment_six"]) != LUA_TNIL ? luabind::object_cast<uint32>(lua_table["augment_six"]) : 0;
const std::string& from_name = luabind::type(lua_table["from_name"]) != LUA_TNIL ? luabind::object_cast<std::string>(lua_table["from_name"]) : std::string();
const std::string& note = luabind::type(lua_table["note"]) != LUA_TNIL ? luabind::object_cast<std::string>(lua_table["note"]) : std::string();
auto e = CharacterParcelsRepository::NewEntity();
e.char_id = character_id;
e.item_id = item_id;
e.aug_slot_1 = augment_one;
e.aug_slot_2 = augment_two;
e.aug_slot_3 = augment_three;
e.aug_slot_4 = augment_four;
e.aug_slot_5 = augment_five;
e.aug_slot_6 = augment_six;
e.slot_id = next_parcel_slot;
e.quantity = quantity;
e.from_name = from_name;
e.note = note;
e.sent_date = std::time(nullptr);
return CharacterParcelsRepository::InsertOne(database, e).id;
}
#define LuaCreateNPCParse(name, c_type, default_value) do { \
cur = table[#name]; \
if(luabind::type(cur) != LUA_TNIL) { \
@@ -6307,6 +6379,7 @@ luabind::scope lua_register_general() {
luabind::def("set_auto_login_character_name_by_account_id", &lua_set_auto_login_character_name_by_account_id),
luabind::def("get_zone_id_by_long_name", &lua_get_zone_id_by_long_name),
luabind::def("get_zone_short_name_by_long_name", &lua_get_zone_short_name_by_long_name),
luabind::def("send_parcel", &lua_send_parcel),
/*
Cross Zone
*/