Pol  Revision:cb584c9
statmsg.cpp
Go to the documentation of this file.
1 
12 #include "statmsg.h"
13 
14 #include "../clib/clib.h"
15 #include "../clib/rawtypes.h"
16 #include "globals/network.h"
17 #include "globals/settings.h"
18 #include "mobile/charactr.h"
19 #include "network/client.h"
20 #include "network/packethelper.h"
21 #include "network/packets.h"
22 #include "ufunc.h"
23 #include "uoclient.h"
24 
25 
26 namespace Pol
27 {
28 namespace Core
29 {
30 using namespace Network::PktHelper;
31 
33 {
35  msg->offset += 2; // msglen
36  msg->Write<u32>( chr->serial_ext );
37  msg->Write( chr->name().c_str(), 30, false );
39  {
41  if ( v > 0xFFFF )
42  v = 0xFFFF;
43  msg->WriteFlipped<u16>( static_cast<u16>( v ) ); // hits
45  if ( v > 0xFFFF )
46  v = 0xFFFF;
47  msg->WriteFlipped<u16>( static_cast<u16>( v ) ); // max_hits
48  }
49  else
50  {
51  msg->WriteFlipped<u16>( 0u ); // hits
52  msg->WriteFlipped<u16>( 0u ); // max_hits
53  }
54  msg->Write<u8>( 0u ); // (client->chr->can_rename( chr ) ? 0xFF : 0);
55  if ( client->ClientType & Network::CLIENTTYPE_70300 )
56  msg->Write<u8>( 6u ); // New entries for classic client
57  else if ( ( client->UOExpansionFlag & Network::ML ) &&
58  ( client->ClientType & Network::CLIENTTYPE_5000 ) )
59  msg->Write<u8>( 5u ); // Set to ML level
60  else if ( ( client->UOExpansionFlag & Network::AOS ) )
61  msg->Write<u8>( 4u ); // Set to AOS level statbar for full info
62  else
63  msg->Write<u8>( 1u ); // Set to oldschool statbar info.
64 
65  // if (chr->race == RACE_ELF)
66  // msg->Write(static_cast<u8>(chr->gender | FLAG_RACE));
67  // else
68  msg->Write<u8>( chr->gender ); // GENDER_MALE or GENDER_FEMALE (see uconst.h)
69 
71  {
73  if ( v > 0xFFFF )
74  v = 0xFFFF;
75  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
76  }
77  else
78  msg->WriteFlipped<u16>( 0u );
79 
81  {
83  if ( v > 0xFFFF )
84  v = 0xFFFF;
85  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
86  }
87  else
88  msg->WriteFlipped<u16>( 0u );
89 
91  {
93  if ( v > 0xFFFF )
94  v = 0xFFFF;
95  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
96  }
97  else
98  msg->WriteFlipped<u16>( 0u );
99 
101  {
103  if ( v > 0xFFFF )
104  v = 0xFFFF;
105  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
106 
108  if ( v > 0xFFFF )
109  v = 0xFFFF;
110  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
111  }
112  else
113  {
114  msg->WriteFlipped<u16>( 0u );
115  msg->WriteFlipped<u16>( 0u );
116  }
117 
119  {
121  if ( v > 0xFFFF )
122  v = 0xFFFF;
123  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
124 
126  if ( v > 0xFFFF )
127  v = 0xFFFF;
128  msg->WriteFlipped<u16>( static_cast<u16>( v ) );
129  }
130  else
131  {
132  msg->WriteFlipped<u16>( 0u );
133  msg->WriteFlipped<u16>( 0u );
134  }
135 
136  msg->WriteFlipped<u32>( chr->gold_carried() );
137  // Adjusted to work with Physical Resist if AOS client, and AOS Resistances enabled.
138  if ( ( client->UOExpansionFlag & Network::AOS ) && client->aosresist )
139  {
140  s16 value = chr->physical_resist().value;
141  msg->WriteFlipped<u16>( static_cast<u16>( ( value < 0 ) ? ( 0x10000 + value ) : value ) );
142  }
143  else
144  msg->WriteFlipped<u16>( chr->ar() );
145 
146  unsigned int weight = chr->weight();
147  Clib::sanitize_upperlimit( &weight, 0xFFFFu );
148  msg->WriteFlipped<u16>( weight );
149 
150  // moreinfo 5
151  if ( ( client->UOExpansionFlag & Network::ML ) &&
152  ( client->ClientType & Network::CLIENTTYPE_5000 ) )
153  {
154  msg->WriteFlipped<u16>( chr->carrying_capacity() );
155  msg->Write<u8>( chr->race + 1u );
156  }
157 
158  // moreinfo 3 start
159  if ( ( client->UOExpansionFlag & Network::AOS ) )
160  {
161  msg->WriteFlipped<s16>( chr->skillstatcap().statcap );
162  auto follow_value = chr->followers();
163  msg->Write<s8>( follow_value.followers );
164  msg->Write<s8>( follow_value.followers_max );
165  // moreinfo 4 start
166  s16 value = chr->fire_resist().value;
167  msg->WriteFlipped<u16>( static_cast<u16>( ( value < 0 ) ? ( 0x10000 + value ) : value ) );
168  value = chr->cold_resist().value;
169  msg->WriteFlipped<u16>( static_cast<u16>( ( value < 0 ) ? ( 0x10000 + value ) : value ) );
170  value = chr->poison_resist().value;
171  msg->WriteFlipped<u16>( static_cast<u16>( ( value < 0 ) ? ( 0x10000 + value ) : value ) );
172  value = chr->energy_resist().value;
173  msg->WriteFlipped<u16>( static_cast<u16>( ( value < 0 ) ? ( 0x10000 + value ) : value ) );
174  msg->WriteFlipped<s16>( chr->luck() );
175  msg->WriteFlipped<u16>( chr->min_weapon_damage() );
176  msg->WriteFlipped<u16>( chr->max_weapon_damage() );
177  msg->WriteFlipped<s32>( chr->tithing() );
178  }
179 
180  // Add the new entries as 0's for now
181  if ( client->ClientType & Network::CLIENTTYPE_70300 )
182  {
183  msg->offset += 30;
184  /*
185  msg->WriteFlipped<u16>( 0 ); // Physical resist cap
186  msg->WriteFlipped<u16>( 0 ); // Fire resist cap
187  msg->WriteFlipped<u16>( 0 ); // Cold resist cap
188  msg->WriteFlipped<u16>( 0 ); // Poison resist cap
189  msg->WriteFlipped<u16>( 0 ); // Energy resist cap
190  msg->WriteFlipped<u16>( 0 ); // Defense chance increase
191  msg->WriteFlipped<u16>( 0 ); // Defense chance cap increase
192  msg->WriteFlipped<u16>( 0 ); // Hit chance increase
193  msg->WriteFlipped<u16>( 0 ); // Swing speed increase
194  msg->WriteFlipped<u16>( 0 ); // Weapon damage increase
195  msg->WriteFlipped<u16>( 0 ); // Lower reagent cose
196  msg->WriteFlipped<u16>( 0 ); // Spell damage increase
197  msg->WriteFlipped<u16>( 0 ); // Faster cast recovery
198  msg->WriteFlipped<u16>( 0 ); // Faster casting
199  msg->WriteFlipped<u16>( 0 ); // Lower mana cost
200  */
201  }
202 
203  u16 len = msg->offset;
204 
205  msg->offset = 1;
206  msg->WriteFlipped<u16>( len );
207  msg.Send( client, len );
208 
210  send_stat_locks( client, chr );
211 }
212 
214 {
215  if ( client->getversiondetail().major < 3 ) // only in AOS, I think
216  return;
217 
218  u8 lockbit = 0;
219 
221  << 4; // XX SS DD II (2 bits for each lock)
222  lockbit |= chr->attribute( networkManager.uoclient_general.dexterity.id ).lock() << 2;
224 
226  msg->WriteFlipped<u16>( 12u );
227  msg->offset += 2; // sub
228  msg->Write<u8>( 0x02u ); // 2D Client = 0x02, KR = 0x05
229  msg->Write<u32>( chr->serial_ext );
230  msg->offset++; // unk
231  msg->Write<u8>( lockbit );
232  msg.Send( client );
233 }
234 
236 {
238  msg->offset += 2; // msglen
239  msg->Write<u32>( chr->serial_ext );
240  msg->Write( chr->name().c_str(), 30, false );
241 
243  {
244  msg->WriteFlipped<u16>( static_cast<u16>(
246  msg->WriteFlipped<u16>( 1000u ); // max_hits
247  }
248  else
249  {
250  msg->WriteFlipped<u16>( 0u ); // hits
251  msg->WriteFlipped<u16>( 0u ); // max_hits
252  }
253  msg->Write<u8>( client->chr->can_rename( chr ) ? 0xFFu : 0u );
254  msg->Write<u8>( 0u ); // moreinfo
255 
256  u16 len = msg->offset;
257  msg->offset = 1;
258  msg->WriteFlipped<u16>( len );
259 
260  msg.Send( client, len );
261 }
262 
264 {
266  msg->Write<u32>( chr->serial_ext );
267 
269  {
271  if ( h > 0xFFFF )
272  h = 0xFFFF;
274  if ( mh > 0xFFFF )
275  mh = 0xFFFF;
276  msg->WriteFlipped<u16>( static_cast<u16>( mh ) );
277  msg->WriteFlipped<u16>( static_cast<u16>( h ) );
278 
279  // Send proper data to self (if we exist?)
280  if ( chr->client && chr->client->ready )
281  msg.Send( chr->client );
282 
283  // To stop "HP snooping"...
284  msg->offset = 5;
285  msg->WriteFlipped<u16>( 1000u );
286  msg->WriteFlipped<u16>( static_cast<u16>( h * 1000 / mh ) );
287  }
288  else
289  {
290  msg->offset += 4; // hits,maxhits=0
291  if ( chr->client && chr->client->ready )
292  msg.Send( chr->client );
293  }
294 
295  // Exclude self... otherwise their status-window shows 1000 hp!! >_<
296  transmit_to_others_inrange( chr, &msg->buffer, msg->offset );
297 }
298 }
299 }
unsigned char u8
Definition: rawtypes.h:25
VersionDetailStruct getversiondetail() const
Definition: client.h:164
unsigned char lock() const
Definition: charactr.h:174
void send_stat_locks(Network::Client *client, Mobile::Character *chr)
Definition: statmsg.cpp:213
void send_short_statmsg(Network::Client *client, Mobile::Character *chr)
Definition: statmsg.cpp:235
Network::Client * client
Definition: charactr.h:871
int current_thousands() const
Definition: charactr.h:194
const u16 ML
Definition: client.h:77
unsigned short max_weapon_damage() const
Definition: charactr.cpp:3127
int current_ones() const
Definition: charactr.h:193
Mobile::Character * chr
Definition: client.h:182
bool can_rename(const Character *chr) const
Definition: charactr.cpp:1236
Core::UGENDER gender
Definition: charactr.h:918
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
const u16 AOS
Definition: client.h:75
signed short s16
Definition: rawtypes.h:30
void sanitize_upperlimit(T *value, const T max)
Definition: clib.h:101
NetworkManager networkManager
Definition: network.cpp:28
void Send(Client *client, int len=-1) const
Definition: packethelper.h:69
const AttributeValue & attribute(unsigned attrid) const
Definition: charactr.h:1051
virtual unsigned short ar() const
Definition: charactr.h:1008
signed int s32
Definition: rawtypes.h:31
signed char s8
Definition: rawtypes.h:29
int maximum_ones() const
Definition: charactr.h:200
Core::URACE race
Definition: charactr.h:919
void send_full_statmsg(Network::Client *client, Mobile::Character *chr)
Definition: statmsg.cpp:32
SettingsManager settingsManager
Definition: settings.cpp:14
void send_update_hits_to_inrange(Mobile::Character *chr)
Definition: statmsg.cpp:263
unsigned int gold_carried() const
Definition: charactr.cpp:1309
const VitalValue & vital(unsigned vitalid) const
Definition: charactr.h:1061
unsigned short carrying_capacity() const
A Mobile&#39;s carrying capacity is (40 + 3.5*STR + chr.carrying_capacity_mod)*ssopt.carrying_capacity_mo...
Definition: charactr.cpp:527
virtual unsigned int weight() const POL_OVERRIDE
A Mobile&#39;s weight is 10 stones + the weight of their equipment.
Definition: charactr.cpp:513
virtual std::string name() const
Definition: uobject.cpp:196
void transmit_to_others_inrange(Character *center, const void *msg, unsigned msglen)
Definition: ufunc.cpp:1518
Definition: berror.cpp:12
unsigned short min_weapon_damage() const
Definition: charactr.cpp:3122
UoClientGeneral uoclient_general
Definition: network.h:67