[Quest API] Add GetItemCooldown to return the time remaining on items… (#2811)

* [Quest API] Add GetItemCooldown to return the time remaining on items in seconds

* Change GetItemCooldown to uint32 for timers up to 130 years
This commit is contained in:
Natedog2012 2023-01-30 00:04:06 -06:00 committed by GitHub
parent 4d2418af9d
commit 66896a3121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 0 deletions

View File

@ -10563,6 +10563,29 @@ void Client::SetItemCooldown(uint32 item_id, bool use_saved_timer, uint32 in_sec
SendItemRecastTimer(recast_type, final_time, true);
}
uint32 Client::GetItemCooldown(uint32 item_id)
{
const EQ::ItemData* item_d = database.GetItem(item_id);
if (!item_d) {
return 0;
}
int recast_type = item_d->RecastType;
auto timestamps = database.GetItemRecastTimestamps(CharacterID());
const auto timer_type = recast_type != RECAST_TYPE_UNLINKED_ITEM ? recast_type : item_id;
uint32 total_time = 0;
uint32 current_time = static_cast<uint32>(std::time(nullptr));
uint32 final_time = 0;
total_time = timestamps.count(timer_type) ? timestamps.at(timer_type) : 0;
if (total_time > current_time) {
final_time = total_time - current_time;
}
return final_time;
}
void Client::RemoveItem(uint32 item_id, uint32 quantity)
{
EQ::ItemInstance *item = nullptr;

View File

@ -968,6 +968,7 @@ public:
int CountItem(uint32 item_id);
void ResetItemCooldown(uint32 item_id);
void SetItemCooldown(uint32 item_id, bool use_saved_timer = false, uint32 in_seconds = 1);
uint32 GetItemCooldown(uint32 item_id);
void RemoveItem(uint32 item_id, uint32 quantity = 1);
bool SwapItem(MoveItem_Struct* move_in);
void SwapItemResync(MoveItem_Struct* move_slots);

View File

@ -3026,6 +3026,12 @@ void Lua_Client::SetItemCooldown(uint32 item_id, uint32 in_time)
self->SetItemCooldown(item_id, false, in_time);
}
uint32 Lua_Client::GetItemCooldown(uint32 item_id)
{
Lua_Safe_Call_Int();
return self->GetItemCooldown(item_id);
}
luabind::scope lua_register_client() {
return luabind::class_<Lua_Client, Lua_Mob>("Client")
.def(luabind::constructor<>())
@ -3216,6 +3222,7 @@ luabind::scope lua_register_client() {
.def("GetInventory", (Lua_Inventory(Lua_Client::*)(void))&Lua_Client::GetInventory)
.def("GetInvulnerableEnvironmentDamage", (bool(Lua_Client::*)(void))&Lua_Client::GetInvulnerableEnvironmentDamage)
.def("GetItemIDAt", (int(Lua_Client::*)(int))&Lua_Client::GetItemIDAt)
.def("GetItemCooldown", (uint32(Lua_Client::*)(uint32))&Lua_Client::GetItemCooldown)
.def("GetLDoNLosses", (int(Lua_Client::*)(void))&Lua_Client::GetLDoNLosses)
.def("GetLDoNLossesTheme", (int(Lua_Client::*)(int))&Lua_Client::GetLDoNLossesTheme)
.def("GetLDoNPointsTheme", (int(Lua_Client::*)(int))&Lua_Client::GetLDoNPointsTheme)

View File

@ -464,6 +464,7 @@ public:
void SendPath(Lua_Mob target);
void ResetItemCooldown(uint32 item_id);
void SetItemCooldown(uint32 item_id, uint32 in_time);
uint32 GetItemCooldown(uint32 item_id);
void ApplySpell(int spell_id);
void ApplySpell(int spell_id, int duration);

View File

@ -2882,6 +2882,11 @@ void Perl_Client_SetItemCooldown(Client* self, uint32 item_id, uint32 in_time)
self->SetItemCooldown(item_id, false, in_time);
}
uint32 Perl_Client_GetItemCooldown(Client* self, uint32 item_id)
{
return self->GetItemCooldown(item_id);
}
void perl_register_client()
{
perl::interpreter perl(PERL_GET_THX);
@ -3076,6 +3081,7 @@ void perl_register_client()
package.add("GetInventory", &Perl_Client_GetInventory);
package.add("GetInvulnerableEnvironmentDamage", &Perl_Client_GetInvulnerableEnvironmentDamage);
package.add("GetItemAt", &Perl_Client_GetItemAt);
package.add("GetItemCooldown", &Perl_Client_GetItemCooldown);
package.add("GetItemIDAt", &Perl_Client_GetItemIDAt);
package.add("GetItemInInventory", &Perl_Client_GetItemInInventory);
package.add("GetLDoNLosses", &Perl_Client_GetLDoNLosses);