mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 06:21:28 +00:00
[Quest API] Add Parcel Sending to Perl/Lua (#4287)
This commit is contained in:
parent
46f3e50b5c
commit
c4cda66c3b
@ -78,6 +78,37 @@ public:
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int GetNextFreeParcelSlot(Database& db, const uint32 character_id, const uint32 max_slots)
|
||||
{
|
||||
const auto& l = CharacterParcelsRepository::GetWhere(
|
||||
db,
|
||||
fmt::format(
|
||||
"char_id = '{}' ORDER BY slot_id ASC",
|
||||
character_id
|
||||
)
|
||||
);
|
||||
|
||||
if (l.empty()) {
|
||||
return PARCEL_BEGIN_SLOT;
|
||||
}
|
||||
|
||||
for (uint32 i = PARCEL_BEGIN_SLOT; i <= max_slots; i++) {
|
||||
auto it = std::find_if(
|
||||
l.cbegin(),
|
||||
l.cend(),
|
||||
[&](const auto &x) {
|
||||
return x.slot_id == i;
|
||||
}
|
||||
);
|
||||
|
||||
if (it == l.end()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return INVALID_INDEX;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_CHARACTER_PARCELS_REPOSITORY_H
|
||||
|
||||
@ -5875,6 +5875,75 @@ std::string Perl__GetZoneShortNameByLongName(std::string zone_long_name)
|
||||
return zone_store.GetZoneShortNameByLongName(zone_long_name);
|
||||
}
|
||||
|
||||
bool Perl__send_parcel(perl::reference table_ref)
|
||||
{
|
||||
perl::hash table = table_ref;
|
||||
if (
|
||||
(!table.exists("name") && !table.exists("character_id")) ||
|
||||
!table.exists("item_id") ||
|
||||
!table.exists("quantity")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string name = table.exists("name") ? table["name"] : "";
|
||||
uint32 character_id = table.exists("character_id") ? 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 = table["item_id"];
|
||||
const int16 quantity = table["quantity"];
|
||||
const uint32 augment_one = table.exists("augment_one") ? table["augment_one"] : 0;
|
||||
const uint32 augment_two = table.exists("augment_two") ? table["augment_two"] : 0;
|
||||
const uint32 augment_three = table.exists("augment_three") ? table["augment_three"] : 0;
|
||||
const uint32 augment_four = table.exists("augment_four") ? table["augment_four"] : 0;
|
||||
const uint32 augment_five = table.exists("augment_five") ? table["augment_five"] : 0;
|
||||
const uint32 augment_six = table.exists("augment_six") ? table["augment_six"] : 0;
|
||||
const std::string& from_name = table.exists("from_name") ? table["from_name"] : std::string();
|
||||
const std::string& note = table.exists("note") ? 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;
|
||||
}
|
||||
|
||||
void perl_register_quest()
|
||||
{
|
||||
perl::interpreter perl(PERL_GET_THX);
|
||||
@ -6704,6 +6773,7 @@ void perl_register_quest()
|
||||
package.add("send_channel_message", (void(*)(uint8, uint32, uint8, uint8, const char*))&Perl__send_channel_message);
|
||||
package.add("send_channel_message", (void(*)(Client*, uint8, uint32, uint8, uint8, const char*))&Perl__send_channel_message);
|
||||
package.add("send_channel_message", (void(*)(Client*, const char*, uint8, uint32, uint8, uint8, const char*))&Perl__send_channel_message);
|
||||
package.add("send_parcel", &Perl__send_parcel);
|
||||
package.add("setaaexpmodifierbycharid", (void(*)(uint32, uint32, double))&Perl__setaaexpmodifierbycharid);
|
||||
package.add("setaaexpmodifierbycharid", (void(*)(uint32, uint32, double, int16))&Perl__setaaexpmodifierbycharid);
|
||||
package.add("set_data", (void(*)(std::string, std::string))&Perl__set_data);
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user