From 9f4d60ec36f7560bcaa662e8ba3ef5686569ef2b Mon Sep 17 00:00:00 2001 From: Jasdac Date: Wed, 3 May 2023 22:19:53 +0200 Subject: [PATCH] [Feature] Intoxication setter/getter for source, getter for Perl/Lua (#3330) * Add setter and getter methods for intoxication Add GetIntoxication functions for perl and Lua * Remove trailing tab * Use clamp instead of min/max --- zone/attack.cpp | 4 ++-- zone/client.cpp | 9 +++++++-- zone/client.h | 3 +++ zone/client_mods.cpp | 12 ++++++------ zone/client_packet.cpp | 6 ++---- zone/client_process.cpp | 4 ++-- zone/lua_client.cpp | 5 +++++ zone/lua_client.h | 1 + zone/perl_client.cpp | 6 ++++++ zone/tune.cpp | 4 ++-- 10 files changed, 36 insertions(+), 18 deletions(-) diff --git a/zone/attack.cpp b/zone/attack.cpp index 21b667a21..ed16e7cb7 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -160,7 +160,7 @@ int Mob::compute_tohit(EQ::skills::SkillType skillinuse) if (IsNPC()) tohit += CastToNPC()->GetAccuracyRating(); if (IsClient()) { - double reduction = CastToClient()->m_pp.intoxication / 2.0; + double reduction = CastToClient()->GetIntoxication() / 2.0; if (reduction > 20.0) { reduction = std::min((110 - reduction) / 100.0, 1.0); tohit = reduction * static_cast(tohit); @@ -256,7 +256,7 @@ int Mob::compute_defense() defense += CastToNPC()->GetAvoidanceRating(); if (IsClient()) { - double reduction = CastToClient()->m_pp.intoxication / 2.0; + double reduction = CastToClient()->GetIntoxication() / 2.0; if (reduction > 20.0) { reduction = std::min((110 - reduction) / 100.0, 1.0); defense = reduction * static_cast(defense); diff --git a/zone/client.cpp b/zone/client.cpp index 23c117d5f..e605a9198 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -908,8 +908,8 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s } // Garble the message based on drunkness - if (m_pp.intoxication > 0 && !(RuleB(Chat, ServerWideOOC) && chan_num == ChatChannel_OOC) && !GetGM()) { - GarbleMessage(message, (int)(m_pp.intoxication / 3)); + if (GetIntoxication() > 0 && !(RuleB(Chat, ServerWideOOC) && chan_num == ChatChannel_OOC) && !GetGM()) { + GarbleMessage(message, (int)(GetIntoxication() / 3)); language = 0; // No need for language when drunk lang_skill = 100; } @@ -8340,6 +8340,11 @@ void Client::SetThirst(int32 in_thirst) safe_delete(outapp); } +void Client::SetIntoxication(int32 in_intoxication) +{ + m_pp.intoxication = EQ::Clamp(in_intoxication, 0, 200); +} + void Client::SetConsumption(int32 in_hunger, int32 in_thirst) { EQApplicationPacket *outapp = nullptr; diff --git a/zone/client.h b/zone/client.h index 59e6cd9bc..17a0ee97d 100644 --- a/zone/client.h +++ b/zone/client.h @@ -67,6 +67,7 @@ namespace EQ #include "task_client_state.h" #include "cheat_manager.h" #include "../common/events/player_events.h" +#include "../common/data_verification.h" #ifdef _WINDOWS // since windows defines these within windef.h (which windows.h include) @@ -993,6 +994,7 @@ public: void SetThirst(int32 in_thirst); void SetConsumption(int32 in_hunger, int32 in_thirst); bool IsStarved() const { if (GetGM() || !RuleB(Character, EnableFoodRequirement) || !RuleB(Character, EnableHungerPenalties)) return false; return m_pp.hunger_level == 0 || m_pp.thirst_level == 0; } + int32 GetIntoxication() const { return m_pp.intoxication; } bool CheckTradeLoreConflict(Client* other); bool CheckTradeNonDroppable(); @@ -1582,6 +1584,7 @@ public: void SetEnvironmentDamageModifier(int32 val) { environment_damage_modifier = val; } inline bool GetInvulnerableEnvironmentDamage() const { return invulnerable_environment_damage; } void SetInvulnerableEnvironmentDamage(bool val) { invulnerable_environment_damage = val; } + void SetIntoxication(int32 in_intoxication); void ShowNumHits(); // work around function for numhits not showing on buffs diff --git a/zone/client_mods.cpp b/zone/client_mods.cpp index 87e77257a..267d2dfc5 100644 --- a/zone/client_mods.cpp +++ b/zone/client_mods.cpp @@ -797,10 +797,10 @@ uint32 Client::CalcCurrentWeight() int32 Client::CalcAlcoholPhysicalEffect() { - if (m_pp.intoxication <= 55) { + if (GetIntoxication() <= 55) { return 0; } - return (m_pp.intoxication - 40) / 16; + return (GetIntoxication() - 40) / 16; } int32 Client::CalcSTR() @@ -878,8 +878,8 @@ int32 Client::CalcINT() int32 val = m_pp.INT + itembonuses.INT + spellbonuses.INT; int32 mod = aabonuses.INT; INT = val + mod; - if (m_pp.intoxication) { - int32 AlcINT = INT - (int32)((float)m_pp.intoxication / 200.0f * (float)INT) - 1; + if (GetIntoxication()) { + int32 AlcINT = INT - (int32)((float)GetIntoxication() / 200.0f * (float)INT) - 1; if ((AlcINT < (int)(0.2 * INT))) { INT = (int)(0.2f * (float)INT); } @@ -902,8 +902,8 @@ int32 Client::CalcWIS() int32 val = m_pp.WIS + itembonuses.WIS + spellbonuses.WIS; int32 mod = aabonuses.WIS; WIS = val + mod; - if (m_pp.intoxication) { - int32 AlcWIS = WIS - (int32)((float)m_pp.intoxication / 200.0f * (float)WIS) - 1; + if (GetIntoxication()) { + int32 AlcWIS = WIS - (int32)((float)GetIntoxication() / 200.0f * (float)WIS) - 1; if ((AlcWIS < (int)(0.2 * WIS))) { WIS = (int)(0.2f * (float)WIS); } diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 6c5ce062c..dc54f1f58 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1309,7 +1309,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) /* If we can maintain intoxication across zones, check for it */ if (!RuleB(Character, MaintainIntoxicationAcrossZones)) - m_pp.intoxication = 0; + SetIntoxication(0); strcpy(name, m_pp.name); strcpy(lastname, m_pp.last_name); @@ -5568,10 +5568,8 @@ void Client::Handle_OP_DeleteItem(const EQApplicationPacket *app) if (IntoxicationIncrease < 0) IntoxicationIncrease = 1; - m_pp.intoxication += IntoxicationIncrease; + SetIntoxication(GetIntoxication()+IntoxicationIncrease); - if (m_pp.intoxication > 200) - m_pp.intoxication = 200; } DeleteItemInInventory(alc->from_slot, 1); diff --git a/zone/client_process.cpp b/zone/client_process.cpp index c48b6fbab..ea88f9934 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -518,9 +518,9 @@ bool Client::Process() { Save(0); } - if (m_pp.intoxication > 0) + if (GetIntoxication() > 0) { - --m_pp.intoxication; + SetIntoxication(GetIntoxication()-1); CalcBonuses(); } diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 21c7651cf..38707c0a6 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -2504,6 +2504,10 @@ int Lua_Client::GetSpellDamage() { Lua_Safe_Call_Int(); return self->GetSpellDmg(); } +int Lua_Client::GetIntoxication() { + Lua_Safe_Call_Int(); + return self->GetIntoxication(); +} void Lua_Client::TaskSelector(luabind::adl::object table) { TaskSelector(table, false); @@ -3237,6 +3241,7 @@ luabind::scope lua_register_client() { .def("GetIPExemption", (int(Lua_Client::*)(void))&Lua_Client::GetIPExemption) .def("GetIPString", (std::string(Lua_Client::*)(void))&Lua_Client::GetIPString) .def("GetInstrumentMod", (int(Lua_Client::*)(int))&Lua_Client::GetInstrumentMod) + .def("GetIntoxication", (int(Lua_Client::*)(void))&Lua_Client::GetIntoxication) .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) diff --git a/zone/lua_client.h b/zone/lua_client.h index 0d5c58bad..14a74db5e 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -395,6 +395,7 @@ public: void QueuePacket(Lua_Packet app, bool ack_req, int client_connection_status, int filter); int GetHunger(); int GetThirst(); + int GetIntoxication(); void SetHunger(int in_hunger); void SetThirst(int in_thirst); void SetConsumption(int in_hunger, int in_thirst); diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index 16c57f321..197554068 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -1522,6 +1522,11 @@ int Perl_Client_GetThirst(Client* self) // @categories Account and Character, St return self->GetThirst(); } +int Perl_Client_GetIntoxication(Client* self) // @categories Account and Character, Stats and Attributes +{ + return self->GetIntoxication(); +} + void Perl_Client_SetHunger(Client* self, int in_hunger) // @categories Script Utility, Stats and Attributes { self->SetHunger(in_hunger); @@ -3093,6 +3098,7 @@ void perl_register_client() package.add("GetHorseId", &Perl_Client_GetHorseId); package.add("GetHealAmount", &Perl_Client_GetHealAmount); package.add("GetHunger", &Perl_Client_GetHunger); + package.add("GetIntoxication", &Perl_Client_GetIntoxication); package.add("GetIP", &Perl_Client_GetIP); package.add("GetIPExemption", &Perl_Client_GetIPExemption); package.add("GetIPString", &Perl_Client_GetIPString); diff --git a/zone/tune.cpp b/zone/tune.cpp index dfeece321..a3ec9825f 100644 --- a/zone/tune.cpp +++ b/zone/tune.cpp @@ -1237,7 +1237,7 @@ int64 Mob::Tunecompute_tohit(EQ::skills::SkillType skillinuse, int accuracy_over tohit += add_accuracy; } if (IsClient()) { - double reduction = CastToClient()->m_pp.intoxication / 2.0; + double reduction = CastToClient()->GetIntoxication() / 2.0; if (reduction > 20.0) { reduction = std::min((110 - reduction) / 100.0, 1.0); tohit = reduction * static_cast(tohit); @@ -1366,7 +1366,7 @@ int64 Mob::Tunecompute_defense(int avoidance_override, int add_avoidance) } if (IsClient()) { - double reduction = CastToClient()->m_pp.intoxication / 2.0; + double reduction = CastToClient()->GetIntoxication() / 2.0; if (reduction > 20.0) { reduction = std::min((110 - reduction) / 100.0, 1.0); defense = reduction * static_cast(defense);