[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
This commit is contained in:
Jasdac 2023-05-03 22:19:53 +02:00 committed by GitHub
parent c64a2aec94
commit 9f4d60ec36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 18 deletions

View File

@ -160,7 +160,7 @@ int Mob::compute_tohit(EQ::skills::SkillType skillinuse)
if (IsNPC()) if (IsNPC())
tohit += CastToNPC()->GetAccuracyRating(); tohit += CastToNPC()->GetAccuracyRating();
if (IsClient()) { if (IsClient()) {
double reduction = CastToClient()->m_pp.intoxication / 2.0; double reduction = CastToClient()->GetIntoxication() / 2.0;
if (reduction > 20.0) { if (reduction > 20.0) {
reduction = std::min((110 - reduction) / 100.0, 1.0); reduction = std::min((110 - reduction) / 100.0, 1.0);
tohit = reduction * static_cast<double>(tohit); tohit = reduction * static_cast<double>(tohit);
@ -256,7 +256,7 @@ int Mob::compute_defense()
defense += CastToNPC()->GetAvoidanceRating(); defense += CastToNPC()->GetAvoidanceRating();
if (IsClient()) { if (IsClient()) {
double reduction = CastToClient()->m_pp.intoxication / 2.0; double reduction = CastToClient()->GetIntoxication() / 2.0;
if (reduction > 20.0) { if (reduction > 20.0) {
reduction = std::min((110 - reduction) / 100.0, 1.0); reduction = std::min((110 - reduction) / 100.0, 1.0);
defense = reduction * static_cast<double>(defense); defense = reduction * static_cast<double>(defense);

View File

@ -908,8 +908,8 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s
} }
// Garble the message based on drunkness // Garble the message based on drunkness
if (m_pp.intoxication > 0 && !(RuleB(Chat, ServerWideOOC) && chan_num == ChatChannel_OOC) && !GetGM()) { if (GetIntoxication() > 0 && !(RuleB(Chat, ServerWideOOC) && chan_num == ChatChannel_OOC) && !GetGM()) {
GarbleMessage(message, (int)(m_pp.intoxication / 3)); GarbleMessage(message, (int)(GetIntoxication() / 3));
language = 0; // No need for language when drunk language = 0; // No need for language when drunk
lang_skill = 100; lang_skill = 100;
} }
@ -8340,6 +8340,11 @@ void Client::SetThirst(int32 in_thirst)
safe_delete(outapp); 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) void Client::SetConsumption(int32 in_hunger, int32 in_thirst)
{ {
EQApplicationPacket *outapp = nullptr; EQApplicationPacket *outapp = nullptr;

View File

@ -67,6 +67,7 @@ namespace EQ
#include "task_client_state.h" #include "task_client_state.h"
#include "cheat_manager.h" #include "cheat_manager.h"
#include "../common/events/player_events.h" #include "../common/events/player_events.h"
#include "../common/data_verification.h"
#ifdef _WINDOWS #ifdef _WINDOWS
// since windows defines these within windef.h (which windows.h include) // since windows defines these within windef.h (which windows.h include)
@ -993,6 +994,7 @@ public:
void SetThirst(int32 in_thirst); void SetThirst(int32 in_thirst);
void SetConsumption(int32 in_hunger, 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; } 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 CheckTradeLoreConflict(Client* other);
bool CheckTradeNonDroppable(); bool CheckTradeNonDroppable();
@ -1582,6 +1584,7 @@ public:
void SetEnvironmentDamageModifier(int32 val) { environment_damage_modifier = val; } void SetEnvironmentDamageModifier(int32 val) { environment_damage_modifier = val; }
inline bool GetInvulnerableEnvironmentDamage() const { return invulnerable_environment_damage; } inline bool GetInvulnerableEnvironmentDamage() const { return invulnerable_environment_damage; }
void SetInvulnerableEnvironmentDamage(bool val) { invulnerable_environment_damage = val; } void SetInvulnerableEnvironmentDamage(bool val) { invulnerable_environment_damage = val; }
void SetIntoxication(int32 in_intoxication);
void ShowNumHits(); // work around function for numhits not showing on buffs void ShowNumHits(); // work around function for numhits not showing on buffs

View File

@ -797,10 +797,10 @@ uint32 Client::CalcCurrentWeight()
int32 Client::CalcAlcoholPhysicalEffect() int32 Client::CalcAlcoholPhysicalEffect()
{ {
if (m_pp.intoxication <= 55) { if (GetIntoxication() <= 55) {
return 0; return 0;
} }
return (m_pp.intoxication - 40) / 16; return (GetIntoxication() - 40) / 16;
} }
int32 Client::CalcSTR() int32 Client::CalcSTR()
@ -878,8 +878,8 @@ int32 Client::CalcINT()
int32 val = m_pp.INT + itembonuses.INT + spellbonuses.INT; int32 val = m_pp.INT + itembonuses.INT + spellbonuses.INT;
int32 mod = aabonuses.INT; int32 mod = aabonuses.INT;
INT = val + mod; INT = val + mod;
if (m_pp.intoxication) { if (GetIntoxication()) {
int32 AlcINT = INT - (int32)((float)m_pp.intoxication / 200.0f * (float)INT) - 1; int32 AlcINT = INT - (int32)((float)GetIntoxication() / 200.0f * (float)INT) - 1;
if ((AlcINT < (int)(0.2 * INT))) { if ((AlcINT < (int)(0.2 * INT))) {
INT = (int)(0.2f * (float)INT); INT = (int)(0.2f * (float)INT);
} }
@ -902,8 +902,8 @@ int32 Client::CalcWIS()
int32 val = m_pp.WIS + itembonuses.WIS + spellbonuses.WIS; int32 val = m_pp.WIS + itembonuses.WIS + spellbonuses.WIS;
int32 mod = aabonuses.WIS; int32 mod = aabonuses.WIS;
WIS = val + mod; WIS = val + mod;
if (m_pp.intoxication) { if (GetIntoxication()) {
int32 AlcWIS = WIS - (int32)((float)m_pp.intoxication / 200.0f * (float)WIS) - 1; int32 AlcWIS = WIS - (int32)((float)GetIntoxication() / 200.0f * (float)WIS) - 1;
if ((AlcWIS < (int)(0.2 * WIS))) { if ((AlcWIS < (int)(0.2 * WIS))) {
WIS = (int)(0.2f * (float)WIS); WIS = (int)(0.2f * (float)WIS);
} }

View File

@ -1309,7 +1309,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app)
/* If we can maintain intoxication across zones, check for it */ /* If we can maintain intoxication across zones, check for it */
if (!RuleB(Character, MaintainIntoxicationAcrossZones)) if (!RuleB(Character, MaintainIntoxicationAcrossZones))
m_pp.intoxication = 0; SetIntoxication(0);
strcpy(name, m_pp.name); strcpy(name, m_pp.name);
strcpy(lastname, m_pp.last_name); strcpy(lastname, m_pp.last_name);
@ -5568,10 +5568,8 @@ void Client::Handle_OP_DeleteItem(const EQApplicationPacket *app)
if (IntoxicationIncrease < 0) if (IntoxicationIncrease < 0)
IntoxicationIncrease = 1; IntoxicationIncrease = 1;
m_pp.intoxication += IntoxicationIncrease; SetIntoxication(GetIntoxication()+IntoxicationIncrease);
if (m_pp.intoxication > 200)
m_pp.intoxication = 200;
} }
DeleteItemInInventory(alc->from_slot, 1); DeleteItemInInventory(alc->from_slot, 1);

View File

@ -518,9 +518,9 @@ bool Client::Process() {
Save(0); Save(0);
} }
if (m_pp.intoxication > 0) if (GetIntoxication() > 0)
{ {
--m_pp.intoxication; SetIntoxication(GetIntoxication()-1);
CalcBonuses(); CalcBonuses();
} }

View File

@ -2504,6 +2504,10 @@ int Lua_Client::GetSpellDamage() {
Lua_Safe_Call_Int(); Lua_Safe_Call_Int();
return self->GetSpellDmg(); return self->GetSpellDmg();
} }
int Lua_Client::GetIntoxication() {
Lua_Safe_Call_Int();
return self->GetIntoxication();
}
void Lua_Client::TaskSelector(luabind::adl::object table) { void Lua_Client::TaskSelector(luabind::adl::object table) {
TaskSelector(table, false); TaskSelector(table, false);
@ -3237,6 +3241,7 @@ luabind::scope lua_register_client() {
.def("GetIPExemption", (int(Lua_Client::*)(void))&Lua_Client::GetIPExemption) .def("GetIPExemption", (int(Lua_Client::*)(void))&Lua_Client::GetIPExemption)
.def("GetIPString", (std::string(Lua_Client::*)(void))&Lua_Client::GetIPString) .def("GetIPString", (std::string(Lua_Client::*)(void))&Lua_Client::GetIPString)
.def("GetInstrumentMod", (int(Lua_Client::*)(int))&Lua_Client::GetInstrumentMod) .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("GetInventory", (Lua_Inventory(Lua_Client::*)(void))&Lua_Client::GetInventory)
.def("GetInvulnerableEnvironmentDamage", (bool(Lua_Client::*)(void))&Lua_Client::GetInvulnerableEnvironmentDamage) .def("GetInvulnerableEnvironmentDamage", (bool(Lua_Client::*)(void))&Lua_Client::GetInvulnerableEnvironmentDamage)
.def("GetItemIDAt", (int(Lua_Client::*)(int))&Lua_Client::GetItemIDAt) .def("GetItemIDAt", (int(Lua_Client::*)(int))&Lua_Client::GetItemIDAt)

View File

@ -395,6 +395,7 @@ public:
void QueuePacket(Lua_Packet app, bool ack_req, int client_connection_status, int filter); void QueuePacket(Lua_Packet app, bool ack_req, int client_connection_status, int filter);
int GetHunger(); int GetHunger();
int GetThirst(); int GetThirst();
int GetIntoxication();
void SetHunger(int in_hunger); void SetHunger(int in_hunger);
void SetThirst(int in_thirst); void SetThirst(int in_thirst);
void SetConsumption(int in_hunger, int in_thirst); void SetConsumption(int in_hunger, int in_thirst);

View File

@ -1522,6 +1522,11 @@ int Perl_Client_GetThirst(Client* self) // @categories Account and Character, St
return self->GetThirst(); 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 void Perl_Client_SetHunger(Client* self, int in_hunger) // @categories Script Utility, Stats and Attributes
{ {
self->SetHunger(in_hunger); self->SetHunger(in_hunger);
@ -3093,6 +3098,7 @@ void perl_register_client()
package.add("GetHorseId", &Perl_Client_GetHorseId); package.add("GetHorseId", &Perl_Client_GetHorseId);
package.add("GetHealAmount", &Perl_Client_GetHealAmount); package.add("GetHealAmount", &Perl_Client_GetHealAmount);
package.add("GetHunger", &Perl_Client_GetHunger); package.add("GetHunger", &Perl_Client_GetHunger);
package.add("GetIntoxication", &Perl_Client_GetIntoxication);
package.add("GetIP", &Perl_Client_GetIP); package.add("GetIP", &Perl_Client_GetIP);
package.add("GetIPExemption", &Perl_Client_GetIPExemption); package.add("GetIPExemption", &Perl_Client_GetIPExemption);
package.add("GetIPString", &Perl_Client_GetIPString); package.add("GetIPString", &Perl_Client_GetIPString);

View File

@ -1237,7 +1237,7 @@ int64 Mob::Tunecompute_tohit(EQ::skills::SkillType skillinuse, int accuracy_over
tohit += add_accuracy; tohit += add_accuracy;
} }
if (IsClient()) { if (IsClient()) {
double reduction = CastToClient()->m_pp.intoxication / 2.0; double reduction = CastToClient()->GetIntoxication() / 2.0;
if (reduction > 20.0) { if (reduction > 20.0) {
reduction = std::min((110 - reduction) / 100.0, 1.0); reduction = std::min((110 - reduction) / 100.0, 1.0);
tohit = reduction * static_cast<double>(tohit); tohit = reduction * static_cast<double>(tohit);
@ -1366,7 +1366,7 @@ int64 Mob::Tunecompute_defense(int avoidance_override, int add_avoidance)
} }
if (IsClient()) { if (IsClient()) {
double reduction = CastToClient()->m_pp.intoxication / 2.0; double reduction = CastToClient()->GetIntoxication() / 2.0;
if (reduction > 20.0) { if (reduction > 20.0) {
reduction = std::min((110 - reduction) / 100.0, 1.0); reduction = std::min((110 - reduction) / 100.0, 1.0);
defense = reduction * static_cast<double>(defense); defense = reduction * static_cast<double>(defense);