diff --git a/Changelog.txt b/Changelog.txt index 034689fd8..4da42259d 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3914,3 +3914,13 @@ Added: 'H' shortcut for variables to get the value as hexadecimal. 13-10-2024, Jhobean - Added: @PetRelease trigger work like @petdesert and return 1 to prevent the pet from being released. + +- Added: @DisplayName give possibility to change the name other player see on the paperdoll and on status bar. Could be use on RP server where unknow person don't know your name before presentation. + Since the name is use at many place, this trigger happen on 3 differents place in the source. + src.: The player requesting to view the name on the paperdoll or status + i: The player stalked by the src. + ARGS (R/W): The name to display + ARGN (R): Tell if trigger is launch on 1:Paperdoll 2:Status 3: Tooltip + RETURN 1 : Change the name to the new value of ARGS + + diff --git a/src/game/CObjBase.h b/src/game/CObjBase.h index e34a42979..db4e6d4a8 100644 --- a/src/game/CObjBase.h +++ b/src/game/CObjBase.h @@ -1072,6 +1072,7 @@ enum CTRIG_TYPE : short CTRIG_DelMulti, // Delete the given multi to the CMultiStorage of this char (player). CTRIG_Destroy, // I am nearly destroyed. CTRIG_Dismount, // I'm dismounting. + CTRIG_DisplayName, // Paperdoll and status is sent and I can change the display name CTRIG_Drink, // I'm drinking something. CTRIG_DYE, CTRIG_Eat, // I'm eating something. diff --git a/src/game/chars/CChar.cpp b/src/game/chars/CChar.cpp index c1b95127a..38e01df37 100644 --- a/src/game/chars/CChar.cpp +++ b/src/game/chars/CChar.cpp @@ -71,6 +71,7 @@ lpctstr const CChar::sm_szTrigName[CTRIG_QTY+1] = // static "@DelMulti", // Removing a multi to the MultiStorage, "@Destroy", //+I am nearly destroyed "@Dismount", // I am trying to get rid of my ride right now + "@DisplayName", // Name Show on the paperdoll and status bar "@Drink", // I am drinking something. "@Dye", // My color has been changed "@Eat", diff --git a/src/game/clients/CClientMsg_AOSTooltip.cpp b/src/game/clients/CClientMsg_AOSTooltip.cpp index 15d3bfc0a..1e3bafaec 100644 --- a/src/game/clients/CClientMsg_AOSTooltip.cpp +++ b/src/game/clients/CClientMsg_AOSTooltip.cpp @@ -35,7 +35,6 @@ bool CClient::addAOSTooltip(CObjBase * pObj, bool fRequested, bool fShop) if (PacketPropertyList::CanSendTo(GetNetState()) == false) return false; - // Enhanced and KR clients always need the tooltips (but they can't be enabled without FEATURE_AOS_UPDATE_B, since this has to be sent to the client via the packet 0xB9). // Shop items use tooltips whether they're disabled or not, // so we can just send a basic tooltip with the item name @@ -68,14 +67,17 @@ bool CClient::addAOSTooltip(CObjBase * pObj, bool fRequested, bool fShop) PacketPropertyList* propertyList = pObj->GetPropertyList(); - if (propertyList == nullptr || propertyList->hasExpired(g_Cfg.m_iTooltipCache)) + CItem* pItem = pObj->IsItem() ? static_cast(pObj) : nullptr; + CChar* pChar = pObj->IsChar() ? static_cast(pObj) : nullptr; + + //If pChar is a client we avoid to use cache because we always generate new tooltip for player. + if ((pChar && pChar->IsClientActive()) || propertyList == nullptr || propertyList->hasExpired(g_Cfg.m_iTooltipCache)) { pObj->m_TooltipData.clear(); pObj->FreePropertyList(); CClientTooltip* t = nullptr; - CItem *pItem = pObj->IsItem() ? static_cast(pObj) : nullptr; - CChar *pChar = pObj->IsChar() ? static_cast(pObj) : nullptr; + //DEBUG_MSG(("Preparing tooltip for 0%x (%s)\n", (dword)pObj->GetUID(), pObj->GetName())); if (fNameOnly) // if we only want to display the name @@ -246,6 +248,22 @@ void CClient::AOSTooltip_addName(CObjBase* pObj) } else if (pChar) { + CChar* pClient = static_cast(GetChar()); + if (IsTrigUsed(TRIGGER_DISPLAYNAME) && pChar->IsClientType() && (pChar != pClient)) //Avoid launch trigger if the target is the same character + { + CScriptTriggerArgs args; + args.m_s1 = pChar->GetName(); + args.m_iN1 = 3;//Trigger use on tooltip + + if (pChar->OnTrigger(CTRIG_DisplayName, pClient, &args) == TRIGRET_RET_TRUE) + { + /*To make it work correctly TooltipCache must be set to 0 on ini or other player will use wrong tooltip*/ + /*Maybe a beter way can be done*/ + PUSH_FRONT_TOOLTIP(pChar, new CClientTooltip(1070722, args.m_s1)); // ~1_NOTHING~ + return; //Avoid to show the prefix and suffix. Show only the name you want + } + } + lpctstr lpPrefix = pChar->GetKeyStr("NAME.PREFIX"); if (!*lpPrefix) @@ -254,6 +272,7 @@ void CClient::AOSTooltip_addName(CObjBase* pObj) if (!*lpPrefix) lpPrefix = " "; + tchar * lpSuffix = Str_GetTemp(); Str_CopyLimitNull(lpSuffix, pChar->GetKeyStr("NAME.SUFFIX"), Str_TempLength()); diff --git a/src/network/send.cpp b/src/network/send.cpp index 50856ed42..ef069b021 100644 --- a/src/network/send.cpp +++ b/src/network/send.cpp @@ -18,6 +18,7 @@ #include "../game/uo_files/uofiles_enums_creid.h" #include "../game/CServer.h" #include "../game/CWorldGameTime.h" +#include "../game/triggers.h" #include "CNetworkManager.h" #include "send.h" @@ -127,14 +128,16 @@ PacketCombatDamage::PacketCombatDamage(const CClient* target, word damage, CUID * * ***************************************************************************/ -PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) : PacketSend(XCMD_Status, 7, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) +PacketObjectStatus::PacketObjectStatus(CClient* target, CObjBase* object) : PacketSend(XCMD_Status, 7, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) { ADDTOCALLSTACK("PacketObjectStatus::PacketObjectStatus"); ASSERT(object); const CNetState * state = target->GetNetState(); - const CChar *character = target->GetChar(); - CChar *objectChar = object->IsChar() ? static_cast(object) : nullptr; + + CChar *character = target->GetChar(); + CChar *objectChar = object->IsChar() ? static_cast(object) : nullptr; + bool fCanRename = false; byte version = 0; @@ -142,7 +145,28 @@ PacketObjectStatus::PacketObjectStatus(const CClient* target, CObjBase* object) initLength(); writeInt32(object->GetUID()); - writeStringFixedASCII(object->GetName(), 30); + + bool bCustomName=0; + CSString sShowName; + if (objectChar != nullptr && + objectChar->IsClientType() && + IsTrigUsed(TRIGGER_DISPLAYNAME) && + (objectChar != character)) //Avoid launch trigger if the target is the same character + { + CScriptTriggerArgs args; + args.m_s1 = object->GetName(); + args.m_iN1 =2;//Trigger use on status + + if (objectChar->OnTrigger(CTRIG_DisplayName, character, &args) == TRIGRET_RET_TRUE) + { + bCustomName = 1; + sShowName = args.m_s1; + } + } + if (bCustomName) + writeStringFixedASCII(sShowName, 30); + else + writeStringFixedASCII(object->GetName(), 30); if (state->isClientVersionNumber(MINCLIVER_STATUS_V6)) version = 6; @@ -2604,7 +2628,7 @@ PacketCharacterListUpdate::PacketCharacterListUpdate(CClient* target, const CCha * * ***************************************************************************/ -PacketPaperdoll::PacketPaperdoll(const CClient* target, const CChar* character) : PacketSend(XCMD_PaperDoll, 66, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) +PacketPaperdoll::PacketPaperdoll(const CClient* target, CChar* character) : PacketSend(XCMD_PaperDoll, 66, g_Cfg.m_fUsePacketPriorities? PRI_LOW : PRI_NORMAL) { ADDTOCALLSTACK("PacketPaperdoll::PacketPaperdoll"); @@ -2619,15 +2643,35 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, const CChar* character) writeInt32(character->GetUID()); + bool bCustomName = 0; + CSString sShowName; + + + if (IsTrigUsed(TRIGGER_DISPLAYNAME) && (target->GetChar() != character)) //Avoid launch trigger if the target is the same character + { + CScriptTriggerArgs args; + args.m_s1 = character->GetName(); + args.m_iN1 = 1;//Trigger use on paperdoll + if (character->OnTrigger(CTRIG_DisplayName, target->GetChar(), &args) == TRIGRET_RET_TRUE) + { + bCustomName = 1; + sShowName = args.m_s1; + } + } + if (character->IsStatFlag(STATF_INCOGNITO)) { writeStringFixedASCII(character->GetName(), 60); - } + } + else if (bCustomName) + { + writeStringFixedASCII(sShowName, 60); + } else { tchar* text = Str_GetTemp(); - int len = 0; + int len = 0; const CStoneMember* guildMember = character->Guild_FindMember(MEMORY_GUILD); if (guildMember != nullptr && guildMember->IsAbbrevOn() && guildMember->GetParentStone()->GetAbbrev()[0]) { @@ -2651,6 +2695,7 @@ PacketPaperdoll::PacketPaperdoll(const CClient* target, const CChar* character) } writeByte((byte)mode); + push(target); } diff --git a/src/network/send.h b/src/network/send.h index 52f5d41a2..b0f732131 100644 --- a/src/network/send.h +++ b/src/network/send.h @@ -111,7 +111,7 @@ class PacketCombatDamage : public PacketSend class PacketObjectStatus : public PacketSend { public: - PacketObjectStatus(const CClient* target, CObjBase* object); + PacketObjectStatus(CClient* target, CObjBase* object); private: void WriteVersionSpecific(const CClient* target, CChar* other, byte version); @@ -948,7 +948,7 @@ class PacketCharacterListUpdate : public PacketSend class PacketPaperdoll : public PacketSend { public: - PacketPaperdoll(const CClient* target, const CChar* character); + PacketPaperdoll(const CClient* target, CChar* character); }; /*************************************************************************** diff --git a/src/tables/triggers.tbl b/src/tables/triggers.tbl index a200f613a..038324cd9 100644 --- a/src/tables/triggers.tbl +++ b/src/tables/triggers.tbl @@ -49,6 +49,7 @@ ADD(DELREDCANDLE) ADD(DELWHITECANDLE) ADD(DESTROY) ADD(DISMOUNT) +ADD(DISPLAYNAME) ADD(DRINK) ADD(DROPON_CHAR) ADD(DROPON_GROUND)