31 #include "../bscript/berror.h" 32 #include "../clib/clib_endian.h" 33 #include "../clib/logfacility.h" 34 #include "../clib/passert.h" 35 #include "../clib/random.h" 36 #include "../clib/rawtypes.h" 37 #include "../plib/systemstate.h" 85 send_sysmessage( client,
"That item is too heavy for the container or the container is full." );
102 send_sysmessage( client,
"The container has no free slots available!" );
108 send_sysmessage( client,
"The container has no free slots available!" );
135 u16 y,
u8 move_type );
141 if ( dropon ==
nullptr || dropon->
client ==
nullptr )
179 if ( dropon ==
nullptr || dropon->
client ==
nullptr )
211 return new Bscript::BError(
"Something went wrong with trade window." );
216 u16 y,
u8 move_type )
235 if ( move_type == 1 )
285 target_item, amtadded );
299 if ( target_serial == cont->
serial )
310 if ( target_item ==
nullptr )
342 if ( item->
no_drop() && !(
static_cast<UContainer*
>( target_item )->no_drop_exception() ) )
373 POLLOG_ERROR.Format(
"Client (Character {}) tried to drop an item out of range.\n" )
382 "Client (Character {}) tried to drop an item at ({},{},{}), which is a blocked " 384 << client->
chr->
name() << x << y << (int)z;
388 LosObj tgt( x, y, static_cast<s8>( newz ), chr->
realm );
399 item->
z =
static_cast<s8>( newz );
412 if ( multi !=
nullptr )
426 for (
unsigned short i = 0; i < 500; ++i )
431 if ( item ==
nullptr )
450 if ( cont->
can_add( *item_to_add ) )
477 send_sysmessage( client,
"You cannot trade with someone in war mode." );
488 send_sysmessage( client,
"That person is already involved in a trade." );
498 send_sysmessage( client,
"That person is already involved in a trade." );
521 return new Bscript::BError(
"You cannot trade with someone in war mode." );
530 return new Bscript::BError(
"That person is already involved in a trade." );
538 return new Bscript::BError(
"That person is already involved in a trade." );
567 msg->WriteFlipped<
u16>(
sizeof msg->buffer );
572 msg->Write<
u8>( 1u );
573 msg->Write( dropon->
name().c_str(), 30, false );
582 msg->Write( client->
chr->
name().c_str(), 30, false );
583 msg.Send( dropon->
client );
585 if ( item !=
nullptr )
596 if ( dropon ==
nullptr )
649 if ( cont ==
nullptr )
690 if ( target_serial == client->
chr->
serial )
700 if ( cont ==
nullptr )
705 if ( cont ==
nullptr )
801 if ( item ==
nullptr )
804 "Character 0x{:X} tried to drop item 0x{:X}, but had not gotten an item.\n" )
808 if ( item->
serial != item_serial )
811 "Character 0x{:X} tried to drop item 0x{:X}, but instead had gotten item 0x{:X}.\n" )
813 item->gotten_by(
nullptr );
816 item->
inuse(
false );
817 item->gotten_by(
nullptr );
818 client->
chr->gotten_item(
nullptr );
821 if ( target_serial == 0xFFffFFffLu )
825 else if ( x == 0xFFFF )
833 if ( multi !=
nullptr )
836 res =
place_item( client, item, target_serial, x, y, 0 );
845 item->
inuse(
false );
846 item->gotten_by(
nullptr );
871 if ( item ==
nullptr )
874 "Character 0x{:X} tried to drop item 0x{:X}, but had not gotten an item.\n" )
878 if ( item->
serial != item_serial )
881 "Character 0x{:X} tried to drop item 0x{:X}, but instead had gotten item 0x{:X}.\n" )
883 item->gotten_by(
nullptr );
886 item->
inuse(
false );
887 item->gotten_by(
nullptr );
888 client->
chr->gotten_item(
nullptr );
891 if ( target_serial == 0xFFffFFffLu )
895 else if ( x == 0xFFFF )
903 if ( multi !=
nullptr )
906 res =
place_item( client, item, target_serial, x, y, 0 );
915 item->
inuse(
false );
916 item->gotten_by(
nullptr );
920 drop_msg.
Send( client );
929 if ( cont ==
nullptr || bp ==
nullptr )
934 while ( !tmp.empty() )
989 msg->WriteFlipped<
u16>( 17u );
1004 msg->WriteFlipped<
u16>( 17u );
1017 unsigned int stat2 = chr->
trading_with->trade_accepted() ? 1 : 0;
1020 msg->WriteFlipped<
u16>( 17u );
1023 msg->WriteFlipped<
u32>( stat1 );
1024 msg->WriteFlipped<
u32>( stat2 );
1029 msg->WriteFlipped<
u32>( stat2 );
1030 msg->WriteFlipped<
u32>( stat1 );
1046 cont0->
swap( *cont1 );
1051 POLLOG_ERROR.Format(
"Can't swap trade containers: ic0={},w0={}, ic1={},w1={}\n" )
1092 if ( client->
ready && client->
chr )
bool place_item(Network::Client *client, Items::Item *item, u32 target_serial, u16 x, u16 y, u8 slotIndex)
virtual void on_insert_add_item(Mobile::Character *mob, MoveType move, Items::Item *new_item)
Contents::const_iterator const_iterator
void register_with_supporting_multi(Item *item)
std::vector< Items::Item * > Contents
bool can_accept_event(Core::EVENTID eventid)
static Item * create(u32 objtype, u32 serial=0)
bool can_add_to_slot(u8 &slotIndex)
bool can_moveanydist() const
void handle_secure_trade_msg(Network::Client *client, PKTBI_6F *msg)
bool can_add_to_self(unsigned short amount, bool force_stacking) const
bool allow_secure_trading_in_warmode
virtual bool can_add(const Items::Item &item) const
void add_item_to_world(Items::Item *item)
bool send_event(Bscript::BObjectImp *event)
bool call(Bscript::BObjectImp *p0)
bool place_item_in_container(Network::Client *client, Items::Item *item, UContainer *cont, u16 x, u16 y, u8 slotIndex)
UContainer * find_giveitem_container(Items::Item *item_to_add, u8 slotIndex)
virtual UObject * toplevel_owner() POL_OVERRIDE
void extract(Contents &cnt)
std::string decint(unsigned short v)
StorageArea * create_area(const std::string &name)
bool drop_item_on_object(Network::Client *client, Items::Item *item, u32 target_serial, u8 slotIndex)
Item * find_legal_item(const Character *chr, u32 serial, bool *additlegal, bool *isRemoteContainer)
void change_trade_status(Mobile::Character *chr, bool set)
void transmit(Client *client, const void *data, int len)
virtual void register_object(UObject *obj)
void send_trade_container(Network::Client *client, Mobile::Character *whos, UContainer *cont)
void send_put_in_container_to_inrange(const Item *item)
void add_to_self(Item *&item)
virtual void add(Items::Item *item)
bool can_swap(const UContainer &cont) const
void send_item_to_inrange(const Item *item)
void swap(UContainer &cont)
#define MOVE_ITEM_FAILURE_TOO_FAR_AWAY
#define ITEM_ELEM_PTR(elem)
void send_item_move_failure(Network::Client *client, u8 reason)
void undo_get_item(Mobile::Character *chr, Items::Item *item)
void send_trade_statuses(Mobile::Character *chr)
void get_random_location(u16 *px, u16 *py) const
Core::UContainer * trade_container()
Multi::UMulti * system_find_multi(u32 serial)
bool drop_item_on_mobile(Network::Client *client, Items::Item *item, u32 target_serial, u8 slotIndex)
void drop_item(Network::Client *client, PKTIN_08_V1 *msg)
virtual unsigned int weight() const POL_OVERRIDE
NetworkManager networkManager
bool drop_item_on_ground(Network::Client *client, Items::Item *item, u16 x, u16 y, s8 z)
bool is_a_parent(const Item *item, u32 serial)
void Send(Client *client, int len=-1) const
Core::CharacterRef trading_with
bool has_los(const Core::ULWObject &att, const Core::ULWObject &tgt) const
#define MOVE_ITEM_FAILURE_UNKNOWN
UContainer * find_legal_container(const Character *chr, u32 serial)
void setrealm(Item *item, void *arg)
void on_insert_increase_stack(Mobile::Character *mob, MoveType move, Items::Item *existing_item, unsigned short amt_added)
void add_at_random_location(Items::Item *item)
Core::UContainer * container
#define GET_ITEM_PTR(itr)
void setname(const std::string &)
void send_remove_object_to_inrange(const UObject *centerObject)
virtual void Send(Client *client) POL_OVERRIDE
void send_full_statmsg(Network::Client *client, Mobile::Character *chr)
Mobile::Character * find_character(u32 serial)
ExportedFunction * can_trade
void move_item(Item *item, UFACING facing)
SettingsManager settingsManager
bool dropheight(unsigned short dropx, unsigned short dropy, short dropz, short chrz, short *newz, Multi::UMulti **pmulti)
virtual unsigned int item_count() const POL_OVERRIDE
ref_ptr< Items::Item > ItemRef
bool IsCharacter(u32 serial)
#define MOVE_ITEM_FAILURE_OUT_OF_SIGHT
Core::UContainer * backpack() const
void restart_decay_timer()
bool no_drop_exception() const
#define INFO_PRINT_TRACE(n)
unsigned short pol_distance(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
void insert_root_item(Items::Item *item)
bool place_item_in_secure_trade_container(Network::Client *client, Items::Item *item, u16 x, u16 y)
Realms::Realm * find_realm(const std::string &name)
bool open_trade_window(Network::Client *client, Items::Item *item, Mobile::Character *dropon)
void create_trade_container()
bool can_insert_increase_stack(Mobile::Character *mob, MoveType move, Items::Item *existing_item, unsigned short amt_to_add, Items::Item *adding_item)
bool isa(UOBJ_CLASS uobj_class) const
void return_traded_items(Mobile::Character *chr)
void drop_item_v2(Network::Client *client, PKTIN_08_V2 *msg)
bool no_drop_exception() const
bool inrangex(const Character *c1, const Character *c2, int maxdist)
virtual std::string name() const
bool trade_accepted() const
void cancel_trade(Mobile::Character *chr1)
bool do_place_item_in_secure_trade_container(Network::Client *client, Items::Item *item, UContainer *cont, Mobile::Character *dropon, u16 x, u16 y, u8 move_type)
bool do_open_trade_window(Network::Client *client, Items::Item *item, Mobile::Character *dropon)
void send_sysmessage(Network::Client *client, const char *text, unsigned short font, unsigned short color)
void send_put_in_container(Client *client, const Item *item)
Items::Item * find_root_item(const std::string &name)
void update_item_to_inrange(const Item *item)
bool add_item_to_stack(Network::Client *client, Items::Item *item, Items::Item *target_item)
virtual void for_each_item(void(*f)(Item *item, void *a), void *arg)
bool can_insert_add_item(Mobile::Character *mob, MoveType move, Items::Item *new_item)