[Quest API] Add Mob-based data bucket methods to Perl/Lua. (#1237)

* Add Mob-based data bucket methods to Perl/Lua.

* Update mob.cpp

* Update perl_mob.cpp
This commit is contained in:
Alex
2021-02-09 00:06:33 -05:00
committed by GitHub
parent ef0398ebd3
commit f2b67ae969
7 changed files with 252 additions and 1 deletions
+49
View File
@@ -20,6 +20,7 @@
#include "../common/string_util.h"
#include "../common/misc_functions.h"
#include "data_bucket.h"
#include "quest_parser_collection.h"
#include "string_ids.h"
#include "worldserver.h"
@@ -5972,3 +5973,51 @@ void Mob::SetCanOpenDoors(bool can_open)
{
m_can_open_doors = can_open;
}
void Mob::DeleteBucket(std::string bucket_name) {
std::string full_bucket_name = fmt::format("{}-{}", GetBucketKey(), bucket_name);
DataBucket::DeleteData(full_bucket_name);
}
std::string Mob::GetBucket(std::string bucket_name) {
std::string full_bucket_name = fmt::format("{}-{}", GetBucketKey(), bucket_name);
std::string bucket_value = DataBucket::GetData(full_bucket_name);
if (!bucket_value.empty()) {
return bucket_value;
}
return std::string();
}
std::string Mob::GetBucketExpires(std::string bucket_name) {
std::string full_bucket_name = fmt::format("{}-{}", GetBucketKey(), bucket_name);
std::string bucket_expiration = DataBucket::GetDataExpires(full_bucket_name);
if (!bucket_expiration.empty()) {
return bucket_expiration;
}
return std::string();
}
std::string Mob::GetBucketKey() {
if (IsClient()) {
return fmt::format("character-{}", CastToClient()->CharacterID());
} else if (IsNPC()) {
return fmt::format("npc-{}", GetNPCTypeID());
}
return std::string();
}
std::string Mob::GetBucketRemaining(std::string bucket_name) {
std::string full_bucket_name = fmt::format("{}-{}", GetBucketKey(), bucket_name);
std::string bucket_remaining = DataBucket::GetDataRemaining(full_bucket_name);
if (!bucket_remaining.empty() && atoi(bucket_remaining.c_str()) > 0) {
return bucket_remaining;
} else if (atoi(bucket_remaining.c_str()) == 0) {
return "0";
}
return std::string();
}
void Mob::SetBucket(std::string bucket_name, std::string bucket_value, std::string expiration) {
std::string full_bucket_name = fmt::format("{}-{}", GetBucketKey(), bucket_name);
DataBucket::SetData(full_bucket_name, bucket_value, expiration);
}