Pol  Revision:cb584c9
movement.cpp
Go to the documentation of this file.
1 
10 #include <stddef.h>
11 
12 #include "../clib/rawtypes.h"
13 #include "mobile/charactr.h"
14 #include "multi/customhouses.h"
15 #include "multi/house.h"
16 #include "multi/multi.h"
17 #include "network/client.h"
18 #include "network/packetdefs.h"
19 #include "network/packethelper.h"
20 #include "network/packets.h"
21 #include "pktdef.h"
22 #include "pktin.h"
23 #include "uconst.h"
24 #include "ufunc.h"
25 #include "uworld.h"
26 
27 namespace Pol
28 {
29 namespace Core
30 {
31 void cancel_trade( Mobile::Character* chr1 );
32 
34 {
35  if ( inrange( chr, client->chr ) &&
36  !inrange( chr->x, chr->y, client->chr->lastx, client->chr->lasty ) &&
37  client->chr->is_visible_to_me( chr ) && client->chr != chr )
38  {
39  send_owncreate( client, chr );
40  }
41 }
42 
44 {
45  if ( inrange( client->chr, item ) &&
46  !inrange( item->x, item->y, client->chr->lastx, client->chr->lasty ) )
47  {
48  send_item( client, item );
49  }
50 }
51 
53 {
54  if ( multi_inrange( client->chr, multi ) &&
55  !multi_inrange( multi->x, multi->y, client->chr->lastx, client->chr->lasty ) )
56  {
57  send_multi( client, multi );
58  Multi::UHouse* house = multi->as_house();
59  if ( ( client->UOExpansionFlag & Network::AOS ) && house != nullptr && house->IsCustom() )
60  Multi::CustomHousesSendShort( house, client );
61  }
62 }
63 
65 {
66  Mobile::Character* chr = client->chr;
67 
69  chr, [&]( Mobile::Character* zonechr ) { send_char_if_newly_inrange( zonechr, client ); } );
71  chr, [&]( Items::Item* zoneitem ) { send_item_if_newly_inrange( zoneitem, client ); } );
73  chr->x, chr->y, chr->realm, RANGE_VISUAL_LARGE_BUILDINGS,
74  [&]( Multi::UMulti* zonemulti ) { send_multi_if_newly_inrange( zonemulti, client ); } );
75 }
76 
78 {
79  Mobile::Character* chr = client->chr;
80 
81  if ( client->ClientType & Network::CLIENTTYPE_7090 )
82  {
84  Multi::UMulti* multi =
85  zonechr->realm->find_supporting_multi( zonechr->x, zonechr->y, zonechr->z );
86 
87  if ( multi != nullptr && multi->serial == serial )
88  return;
89 
90  send_char_if_newly_inrange( zonechr, client );
91  } );
93  Multi::UMulti* multi =
94  zoneitem->realm->find_supporting_multi( zoneitem->x, zoneitem->y, zoneitem->z );
95 
96  if ( multi != nullptr && multi->serial == serial )
97  return;
98 
99  send_item_if_newly_inrange( zoneitem, client );
100  } );
102  [&]( Multi::UMulti* zonemulti ) {
103  if ( zonemulti->serial == serial )
104  return;
105 
106  send_multi_if_newly_inrange( zonemulti, client );
107  } );
108  }
109  else
110  {
112  chr, [&]( Mobile::Character* zonechr ) { send_char_if_newly_inrange( zonechr, client ); } );
114  chr, [&]( Items::Item* zoneitem ) { send_item_if_newly_inrange( zoneitem, client ); } );
116  chr->x, chr->y, chr->realm, RANGE_VISUAL_LARGE_BUILDINGS,
117  [&]( Multi::UMulti* zonemulti ) { send_multi_if_newly_inrange( zonemulti, client ); } );
118  }
119 }
120 
122 {
123  Mobile::Character* chr = client->chr;
124  Network::RemoveObjectPkt msgremove( chr->serial_ext );
125 
127  send_remove_character( client, zonechar, msgremove );
128  } );
130  chr, [&]( Items::Item* item ) { send_remove_object( client, item, msgremove ); } );
132  chr->x, chr->y, chr->realm, RANGE_VISUAL_LARGE_BUILDINGS,
133  [&]( Multi::UMulti* multi ) { send_remove_object( client, multi, msgremove ); } );
134 }
135 
136 
137 void handle_walk( Network::Client* client, PKTIN_02* msg02 )
138 {
139  Mobile::Character* chr = client->chr;
140 
141  if ( ( client->movementsequence == 0 ) && ( msg02->movenum != 0 ) )
142  {
143  // drop pkt if last request was denied, should fix the "client hopping"
144 
145  /*PktHelper::PacketOut<PktOut_21> msg;
146  msg->Write<u8>(msg02->movenum);
147  msg->WriteFlipped<u16>(chr->x);
148  msg->WriteFlipped<u16>(chr->y);
149  msg->Write<u8>(chr->facing);
150  msg->Write<s8>(chr->z);
151  msg.Send(client);*/
152 
153  return;
154  }
155  else
156  {
157  u8 oldfacing = chr->facing;
158 
159  if ( chr->move( msg02->dir ) )
160  {
161  // If facing is dir they are walking, check to see if already 4 tiles away
162  // from the person trading with. If so, cancel trading!!!!
164  {
165  if ( chr->is_trading() )
166  {
167  if ( ( oldfacing == ( msg02->dir & PKTIN_02_FACING_MASK ) ) &&
168  ( pol_distance( chr->x, chr->y, chr->trading_with->x, chr->trading_with->y ) > 3 ) )
169  {
170  cancel_trade( chr );
171  }
172  }
173  }
174  client->pause();
176  msg->Write<u8>( msg02->movenum );
177  msg->Write<u8>( client->chr->hilite_color_idx( client->chr ) );
178  msg.Send( client );
179 
180  client->movementsequence = msg02->movenum;
181  if ( client->movementsequence == 255 )
182  client->movementsequence = 1;
183  else
184  client->movementsequence++;
185 
186 
187  // FIXME: Make sure we only tell those who can see us.
188  chr->tellmove();
189 
190  send_objects_newly_inrange( client );
191 
192  client->restart();
193 
194  // here we set the delay for SpeedHackPrevention see Client::SpeedHackPrevention()
195  if ( oldfacing == ( msg02->dir & PKTIN_02_FACING_MASK ) )
196  {
197  if ( client->chr->on_mount() )
198  client->next_movement += ( msg02->dir & PKTIN_02_DIR_RUNNING_BIT )
201  else
202  client->next_movement += ( msg02->dir & PKTIN_02_DIR_RUNNING_BIT )
205  }
206  else // changing only facing is fast
208  }
209  else
210  {
212  msg->Write<u8>( msg02->movenum );
213  msg->WriteFlipped<u16>( chr->x );
214  msg->WriteFlipped<u16>( chr->y );
215  msg->Write<u8>( chr->facing );
216  msg->Write<s8>( chr->z );
217  msg.Send( client );
218  client->movementsequence = 0;
219  }
220  }
221 }
222 }
223 }
unsigned char u8
Definition: rawtypes.h:25
void send_multi_if_newly_inrange(Multi::UMulti *multi, Network::Client *client)
Definition: movement.cpp:52
void send_objects_newly_inrange(Network::Client *client)
Definition: movement.cpp:64
void send_multi(Network::Client *client, const Multi::UMulti *multi)
Definition: ufunc.cpp:1652
void send_item_if_newly_inrange(Items::Item *item, Network::Client *client)
Definition: movement.cpp:43
unsigned short speedhack_footrundelay
Definition: ssopt.h:89
#define RANGE_VISUAL_LARGE_BUILDINGS
Definition: uconst.h:73
unsigned short speedhack_footwalkdelay
Definition: ssopt.h:90
bool is_visible_to_me(const Character *chr) const
Definition: charactr.cpp:2658
bool inrange(const UObject *c1, unsigned short x, unsigned short y)
Definition: ufunc.cpp:454
static void InRange(u16 x, u16 y, const Realms::Realm *realm, unsigned range, F &&f)
Definition: uworld.h:235
bool on_mount() const
Definition: charactr.cpp:1490
Mobile::Character * chr
Definition: client.h:182
Clib::wallclock_t next_movement
Definition: client.h:262
unsigned short u16
Definition: rawtypes.h:26
unsigned int u32
Definition: rawtypes.h:27
void send_remove_character(Client *client, const Character *chr)
Definition: ufunc.cpp:355
const u16 AOS
Definition: client.h:75
bool move(unsigned char dir)
Definition: charactr.cpp:3757
virtual class UHouse * as_house()
Definition: multis.cpp:55
void Send(Client *client, int len=-1) const
Definition: packethelper.h:69
void send_remove_object(Client *client, const UObject *object)
Definition: ufunc.cpp:420
Core::CharacterRef trading_with
Definition: charactr.h:857
bool is_trading() const
Definition: charactr.cpp:4117
bool IsCustom() const
Definition: house.h:84
virtual unsigned char hilite_color_idx(const Character *seen_by) const
Definition: repsys.cpp:981
signed char s8
Definition: rawtypes.h:29
void send_objects_newly_inrange_on_boat(Network::Client *client, u32 serial)
Definition: movement.cpp:77
SettingsManager settingsManager
Definition: settings.cpp:14
static void InVisualRange(const UObject *obj, F &&f)
Definition: uworld.h:245
void send_char_if_newly_inrange(Mobile::Character *chr, Network::Client *client)
Definition: movement.cpp:33
void send_item(Client *client, const Item *item)
Definition: ufunc.cpp:676
void remove_objects_inrange(Network::Client *client)
Definition: movement.cpp:121
#define PKTIN_02_DIR_RUNNING_BIT
Definition: pktdef.h:76
#define PKTIN_02_FACING_MASK
Definition: pktdef.h:75
unsigned short pol_distance(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
Definition: ufunc.cpp:481
Realms::Realm * realm
Definition: baseobject.h:56
bool allow_moving_trade
Definition: ssopt.h:64
void handle_walk(Network::Client *client, PKTIN_02 *msg02)
Definition: movement.cpp:137
unsigned short speedhack_mountrundelay
Definition: ssopt.h:87
Multi::UMulti * find_supporting_multi(unsigned short x, unsigned short y, short z) const
Definition: realmfunc.cpp:709
void send_owncreate(Client *client, const Character *chr)
Definition: ufunc.cpp:206
void cancel_trade(Mobile::Character *chr1)
Definition: dropitem.cpp:979
Definition: berror.cpp:12
unsigned short speedhack_mountwalkdelay
Definition: ssopt.h:88
bool multi_inrange(const Mobile::Character *c1, const Multi::UMulti *obj)
Definition: ufunc.cpp:474
void CustomHousesSendShort(UHouse *house, Network::Client *client)