Pol  Revision:cb584c9
eqpitem.cpp
Go to the documentation of this file.
1 
10 #include <cstdio>
11 
12 #include "../clib/clib_endian.h"
13 #include "../clib/logfacility.h"
14 #include "../clib/rawtypes.h"
15 #include "item/item.h"
16 #include "layers.h"
17 #include "mobile/charactr.h"
18 #include "multi/multi.h"
19 #include "network/client.h"
20 #include "pktdef.h"
21 #include "pktin.h"
22 #include "realms/realm.h"
23 #include "reftypes.h"
24 #include "ufunc.h"
25 
26 namespace Pol
27 {
28 namespace Core
29 {
30 void equip_item( Network::Client* client, PKTIN_13* msg )
31 {
32  u32 serial = cfBEu32( msg->serial );
33  u8 layer = msg->layer;
34  u32 equip_on_serial = cfBEu32( msg->equipped_on );
35 
36  if ( ( layer > HIGHEST_LAYER ) || ( layer == 0 ) || client->chr->dead() )
37  {
39  return;
40  }
41 
42  Items::Item* item = client->chr->gotten_item();
43 
44  if ( item == nullptr )
45  {
46  POLLOG_ERROR.Format(
47  "Character 0x{:X} tried to equip item 0x{:X}, which did not exist in gotten_items.\n" )
48  << client->chr->serial << serial;
50  return;
51  }
52 
53  if ( item->serial != serial )
54  {
55  POLLOG_ERROR.Format(
56  "Character 0x{:X} tried to equip item 0x{:X}, but had gotten item 0x{:X}\n" )
57  << client->chr->serial << serial << item->serial;
59  item->gotten_by( nullptr );
60  return;
61  }
62 
63  ItemRef itemref( item );
64 
65  item->layer = item->tile_layer;
66  item->inuse( false );
67  item->gotten_by( nullptr );
68  client->chr->gotten_item( nullptr );
69 
70  Mobile::Character* equip_on = nullptr;
71  if ( equip_on_serial == client->chr->serial )
72  {
73  equip_on = client->chr;
74  }
75  else
76  {
77  equip_on = find_character( equip_on_serial );
78  if ( equip_on == nullptr || !client->chr->can_clothe( equip_on ) )
79  {
81 
82  undo_get_item( client->chr, item );
83  return;
84  }
85  }
86 
87  if ( equip_on->layer_is_equipped( item->tile_layer ) )
88  {
89  // it appears the client already checks for this, so this code hasn't been exercised.
90  // we'll assume client mouse holds on to object
91  // 3D Client doesn't check for this!
93 
94  undo_get_item( client->chr, item ); // added 11/01/03 for 3d client
95  return;
96  }
97 
98  if ( !equip_on->strong_enough_to_equip( item ) )
99  {
101  // the client now puts the item back where it was before.
102 
103  // return the item to wherever it was. (?)
104  undo_get_item( client->chr, item );
105  if ( client->chr == equip_on )
106  {
107  send_sysmessage( client, "You are not strong enough to use that." );
108  }
109  else
110  {
111  send_sysmessage( client, "Insufficient strength to equip that." );
112  }
113  return;
114  }
115 
116  if ( !equip_on->equippable( item ) || !item->check_equiptest_scripts( equip_on ) ||
117  !item->check_equip_script( equip_on, false ) )
118  {
120  if ( item->orphan() )
121  {
122  return;
123  }
124  undo_get_item( client->chr, item );
125  return;
126  }
127 
128  if ( item->orphan() )
129  {
130  return;
131  }
132 
133  // Unregister the item if it is on a multi
134  if ( item->container == nullptr && !item->has_gotten_by() )
135  {
136  Multi::UMulti* multi = item->realm->find_supporting_multi( item->x, item->y, item->z );
137 
138  if ( multi != nullptr )
139  multi->unregister_object( item );
140  }
141 
142  equip_on->equip( item );
143  send_wornitem_to_inrange( equip_on, item );
144 }
145 }
146 }
void equip_item(Network::Client *client, PKTIN_13 *msg)
Definition: eqpitem.cpp:30
unsigned char u8
Definition: rawtypes.h:25
bool strong_enough_to_equip(const Items::Item *item) const
Definition: charactr.cpp:1350
#define MOVE_ITEM_FAILURE_ALREADY_WORN
Definition: pktdef.h:34
#define cfBEu32(x)
Definition: clib_endian.h:43
#define POLLOG_ERROR
Definition: logfacility.h:207
Mobile::Character * chr
Definition: client.h:182
void send_item_move_failure(Network::Client *client, u8 reason)
Definition: ufunc.cpp:818
void undo_get_item(Mobile::Character *chr, Items::Item *item)
Definition: getitem.cpp:260
unsigned int u32
Definition: rawtypes.h:27
#define MOVE_ITEM_FAILURE_ILLEGAL_EQUIP
Definition: pktdef.h:35
bool check_equip_script(Mobile::Character *chr, bool startup)
Definition: item.cpp:1051
bool orphan() const
Definition: baseobject.h:119
Core::UContainer * container
Definition: item.h:256
Mobile::Character * find_character(u32 serial)
Definition: fnsearch.cpp:60
void equip(Items::Item *item)
Definition: charactr.cpp:1433
ref_ptr< Items::Item > ItemRef
Definition: reftypes.h:43
bool can_clothe(const Character *chr) const
Definition: charactr.cpp:1241
Realms::Realm * realm
Definition: baseobject.h:56
void send_wornitem_to_inrange(const Character *chr, const Item *item)
Definition: ufunc.cpp:842
bool check_equiptest_scripts(Mobile::Character *chr, bool startup=false)
Definition: item.cpp:1137
bool inuse() const
Definition: item.h:314
bool equippable(const Items::Item *item) const
Definition: charactr.cpp:1356
Multi::UMulti * find_supporting_multi(unsigned short x, unsigned short y, short z) const
Definition: realmfunc.cpp:709
virtual void unregister_object(UObject *obj)
Definition: multis.cpp:62
bool layer_is_equipped(int layer) const
Definition: charactr.cpp:1337
Definition: berror.cpp:12
bool dead() const
Definition: charactr.h:931
void send_sysmessage(Network::Client *client, const char *text, unsigned short font, unsigned short color)
Definition: ufunc.cpp:1147