Pol  Revision:cb584c9
tooltips.cpp
Go to the documentation of this file.
1 
13 #include "tooltips.h"
14 
15 #include <stddef.h>
16 #include <string>
17 
18 #include "../clib/clib_endian.h"
19 #include "../clib/rawtypes.h"
20 #include "item/item.h"
21 #include "item/itemdesc.h"
22 #include "mobile/charactr.h"
23 #include "network/client.h"
24 #include "network/packetdefs.h"
25 #include "network/packethelper.h"
26 #include "network/packets.h"
27 #include "pktin.h"
28 #include "ufunc.h"
29 #include "uobject.h"
30 #include "uworld.h"
31 
32 namespace Pol
33 {
34 namespace Core
35 {
36 using namespace Network::PktHelper;
37 
38 
40 {
41  u32 serial = cfBEu32( msgin->serial );
42  if ( !IsCharacter( serial ) )
43  {
44  Items::Item* item = find_legal_item( client->chr, serial );
45  if ( item != nullptr )
46  {
47  const Items::ItemDesc& id = item->itemdesc();
48  if ( !id.tooltip.empty() )
49  {
51  msg->offset += 2;
52  msg->Write<u32>( item->serial_ext );
53  const char* string = id.tooltip.c_str();
54  while ( *string ) // unicode
55  msg->Write<u16>( static_cast<u16>( ( *string++ ) << 8 ) );
56  msg->offset += 2; // nullterm
57  u16 len = msg->offset;
58  msg->offset = 1;
59  msg->WriteFlipped<u16>( len );
60  msg.Send( client, len );
61  }
62  }
63  }
64 }
65 
66 // needed if A9 flag is sent with 0x20, single click no longer works. see about text# 1042971 for
67 // 0xD6
68 void send_object_cache( Network::Client* client, const UObject* obj )
69 {
71  {
72  auto pkt_rev = Network::ObjRevisionPkt( obj->serial_ext, obj->rev() );
73  pkt_rev.Send( client );
74  }
75 }
76 
78 {
80  {
81  auto pkt_rev = Network::ObjRevisionPkt( obj->serial_ext, obj->rev() );
82 
84  [&]( Mobile::Character* chr ) {
85  pkt_rev.Send( chr->client );
86  // FIXME need to check character's
87  // additional_legal_items.
88  } );
89  }
90 }
91 
92 
93 void SendAOSTooltip( Network::Client* client, UObject* obj, bool vendor_content )
94 {
95  std::string desc;
96  if ( obj->isa( UOBJ_CLASS::CLASS_CHARACTER ) )
97  {
99  desc = ( !chr->has_title_prefix() ? " \t" : chr->title_prefix() + " \t" ) + chr->name() +
100  ( !chr->has_title_suffix() ? "\t " : "\t " + chr->title_suffix() );
101  if ( chr->has_title_race() )
102  desc += " (" + chr->title_race() + ")";
103  if ( chr->has_title_guild() )
104  desc += " [" + chr->title_guild() + "]";
105  }
106  else if ( vendor_content )
107  {
108  Items::Item* item = (Items::Item*)obj;
109  desc = item->merchant_description();
110  }
111  else
112  desc = obj->description();
113 
115  msg->offset += 2;
116  msg->WriteFlipped<u16>( 1u ); // u16 unk1
117  msg->Write<u32>( obj->serial_ext );
118  msg->offset += 2; // u8 unk2,unk3
119  msg->WriteFlipped<u32>( obj->rev() );
120  if ( obj->isa( UOBJ_CLASS::CLASS_CHARACTER ) )
121  msg->WriteFlipped<u32>( 1050045u ); // 1 text argument only
122  else
123  msg->WriteFlipped<u32>( 1042971u ); // 1 text argument only
124 
125  u16 textlen = static_cast<u16>( desc.size() );
126  if ( ( textlen * 2 ) > ( 0xFFFF - 22 ) )
127  {
128  textlen = 0xFFFF / 2 - 22;
129  }
130  msg->WriteFlipped<u16>( textlen * 2u );
131  const char* string = desc.c_str();
132 
133  while ( *string && textlen-- ) // unicode
134  msg->Write<u16>( static_cast<u16>( *string++ ) );
135  msg->offset += 4; // indicates end of property list
136  u16 len = msg->offset;
137  msg->offset = 1;
138  msg->WriteFlipped<u16>( len );
139  msg.Send( client, len );
140 }
141 }
142 }
virtual void Send(Client *client) POL_OVERRIDE
Definition: packetdefs.cpp:442
#define cfBEu32(x)
Definition: clib_endian.h:43
std::string merchant_description() const
Definition: item.cpp:177
Item * find_legal_item(const Character *chr, u32 serial, bool *additlegal, bool *isRemoteContainer)
Definition: ufunc.cpp:958
Mobile::Character * chr
Definition: client.h:182
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
void Send(Client *client, int len=-1) const
Definition: packethelper.h:69
void SendAOSTooltip(Network::Client *client, UObject *obj, bool vendor_content)
Definition: tooltips.cpp:93
unsigned short uo_feature_enable
Definition: ssopt.h:57
virtual UObject * toplevel_owner()
Definition: uobject.cpp:234
SettingsManager settingsManager
Definition: settings.cpp:14
static void InVisualRange(const UObject *obj, F &&f)
Definition: uworld.h:245
void handle_request_tooltip(Network::Client *client, PKTIN_B6 *msgin)
Definition: tooltips.cpp:39
bool IsCharacter(u32 serial)
Definition: uobject.h:311
u32 rev() const
Definition: uobject.h:220
bool isa(UOBJ_CLASS uobj_class) const
Definition: baseobject.h:99
const ItemDesc & itemdesc() const
Definition: item.cpp:127
void send_object_cache_to_inrange(const UObject *obj)
Definition: tooltips.cpp:77
void send_object_cache(Network::Client *client, const UObject *obj)
Definition: tooltips.cpp:68
virtual std::string description() const
Definition: uobject.cpp:201
virtual std::string name() const
Definition: uobject.cpp:196
Definition: berror.cpp:12