Pol  Revision:cb584c9
sngclick.cpp
Go to the documentation of this file.
1 
8 #include "sngclick.h"
9 
10 #include <cstdio>
11 #include <string>
12 
13 #include "../clib/clib_endian.h"
14 #include "../clib/passert.h"
15 #include "containr.h"
16 #include "mobile/charactr.h"
17 #include "network/client.h"
18 #include "pktin.h"
19 #include "uconst.h"
20 #include "ufunc.h"
21 #include "ufuncstd.h"
22 #include "uobject.h"
23 #include "uworld.h"
24 
25 
26 namespace Pol
27 {
28 namespace Core
29 {
31 {
32  Items::Item* item = find_legal_item( chr, serial );
33  if ( item )
34  return item;
35 
36  // search equipment of nearby mobiles
37  unsigned short wxL, wyL, wxH, wyH;
38  zone_convert_clip( chr->x - RANGE_VISUAL, chr->y - RANGE_VISUAL, chr->realm, &wxL, &wyL );
39  zone_convert_clip( chr->x + RANGE_VISUAL, chr->y + RANGE_VISUAL, chr->realm, &wxH, &wyH );
40  for ( unsigned short wx = wxL; wx <= wxH; ++wx )
41  {
42  for ( unsigned short wy = wyL; wy <= wyH; ++wy )
43  {
44  for ( const auto& ochr : chr->realm->zone[wx][wy].characters )
45  {
46  Items::Item* _item = ochr->find_wornitem( serial );
47  if ( _item != nullptr )
48  return _item;
49  }
50  for ( const auto& ochr : chr->realm->zone[wx][wy].npcs )
51  {
52  Items::Item* _item = ochr->find_wornitem( serial );
53  if ( _item != nullptr )
54  return _item;
55  }
56  }
57  }
58  if ( chr->trade_container() )
59  {
60  item = chr->trade_container()->find( serial );
61  if ( item )
62  return item;
63  }
64  if ( chr->trading_with.get() && chr->trading_with->trade_container() )
65  {
66  item = chr->trading_with->trade_container()->find( serial );
67  if ( item )
68  return item;
69  }
70 
71  return nullptr;
72 }
73 
75 {
76  std::string tags;
77 
78  if ( chr->frozen() && ( settingsManager.ssopt.core_handled_tags & 0x2 ) )
79  tags = "[frozen] ";
80  if ( chr->paralyzed() && ( settingsManager.ssopt.core_handled_tags & 0x4 ) )
81  tags += "[paralyzed] ";
82  if ( chr->squelched() && ( settingsManager.ssopt.core_handled_tags & 0x8 ) )
83  tags += "[squelched] ";
84  if ( chr->deafened() && ( settingsManager.ssopt.core_handled_tags & 0x10 ) )
85  tags += "[deafened] ";
86  if ( chr->invul() && settingsManager.ssopt.invul_tag == 1 )
87  tags += "[invulnerable]";
88 
89  return tags;
90 }
91 
92 void singleclick( Network::Client* client, u32 serial )
93 {
94  passert_always( client != nullptr && client->chr != nullptr );
95 
96  if ( IsCharacter( serial ) )
97  {
98  Mobile::Character* chr = nullptr;
99  if ( serial == client->chr->serial )
100  chr = client->chr;
101  else
102  chr = find_character( serial );
103 
104  if ( chr != nullptr && inrange( client->chr, chr ) &&
105  !client->chr->is_concealed_from_me( chr ) )
106  {
107  if ( chr->has_title_guild() && ( settingsManager.ssopt.core_handled_tags & 0x1 ) )
108  send_nametext( client, chr, "[" + chr->title_guild() + "]" );
109  send_nametext( client, chr, chr->name() );
110 
111  std::string tags = create_nametags( chr );
112  if ( !tags.empty() )
113  send_nametext( client, chr, tags );
114  }
115  }
116  else // single clicked on an item
117  {
118  Items::Item* item = find_legal_singleclick_item( client->chr, serial );
119  if ( item )
120  {
121  send_objdesc( client, item );
122  }
123  }
124 }
125 
127 {
128  u32 serial = cfBEu32( msg->serial );
129  if ( client && client->chr )
130  singleclick( client, serial );
131  // TODO: report if someone tries to use singleclick without a connected char (should have been
132  // blocked)
133 }
134 }
135 }
u16 wyH
Definition: uworld.h:181
void singleclick(Network::Client *client, u32 serial)
Definition: sngclick.cpp:92
void send_nametext(Client *client, const Character *chr, const std::string &str)
Definition: ufunc.cpp:1237
bool deafened() const
Definition: charactr.cpp:4061
u16 wyL
Definition: uworld.h:179
#define cfBEu32(x)
Definition: clib_endian.h:43
Items::Item * find(u32 serial) const
Definition: containr.cpp:620
bool inrange(const UObject *c1, unsigned short x, unsigned short y)
Definition: ufunc.cpp:454
bool frozen() const
Definition: charactr.h:969
Item * find_legal_item(const Character *chr, u32 serial, bool *additlegal, bool *isRemoteContainer)
Definition: ufunc.cpp:958
unsigned short core_handled_tags
Definition: ssopt.h:79
Mobile::Character * chr
Definition: client.h:182
ZoneCharacters characters
Definition: uworld.h:70
unsigned int u32
Definition: rawtypes.h:27
void zone_convert_clip(int x, int y, const Realms::Realm *realm, unsigned short *wx, unsigned short *wy)
Definition: uworld.h:86
Items::Item * find_legal_singleclick_item(Mobile::Character *chr, u32 serial)
Definition: sngclick.cpp:30
#define RANGE_VISUAL
Definition: uconst.h:72
Core::UContainer * trade_container()
Definition: charactr.cpp:4142
u16 wxH
Definition: uworld.h:180
Core::CharacterRef trading_with
Definition: charactr.h:857
bool paralyzed() const
Definition: charactr.h:974
std::string create_nametags(Mobile::Character *chr)
Definition: sngclick.cpp:74
unsigned short invul_tag
Definition: ssopt.h:56
Mobile::Character * find_character(u32 serial)
Definition: fnsearch.cpp:60
SettingsManager settingsManager
Definition: settings.cpp:14
bool is_concealed_from_me(const Character *chr) const
Definition: charactr.cpp:2653
void handle_singleclick(Network::Client *client, PKTIN_09 *msg)
Definition: sngclick.cpp:126
ZoneCharacters npcs
Definition: uworld.h:71
bool IsCharacter(u32 serial)
Definition: uobject.h:311
Realms::Realm * realm
Definition: baseobject.h:56
Core::Zone ** zone
Definition: realm.h:133
u16 wxL
Definition: uworld.h:178
#define passert_always(exp)
Definition: passert.h:80
virtual std::string name() const
Definition: uobject.cpp:196
bool squelched() const
Definition: charactr.cpp:4042
Definition: berror.cpp:12
void send_objdesc(Client *client, Item *item)
Definition: ufunc.cpp:1425
bool invul() const
Definition: charactr.cpp:4080