--- deliantra/server/common/object.C 2008/04/23 07:25:54 1.218 +++ deliantra/server/common/object.C 2008/04/24 12:06:01 1.221 @@ -336,7 +336,7 @@ object * object::visible_to () const { - if (!flag [FLAG_REMOVED]) + if (client_visible () && !flag [FLAG_REMOVED]) { // see if we are in a container of sorts if (env) @@ -360,7 +360,8 @@ // maybe there is a player standing on the same mapspace // this will catch the case where "this" is a player if (object *pl = ms ().player ()) - return pl; + if (!pl->container || this == pl->container) + return pl; } } @@ -1028,6 +1029,12 @@ if (destroyed ()) return; + if (!is_head () && !head->destroyed ()) + { + LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); + head->destroy (destroy_inventory); + } + destroy_inv (!destroy_inventory); if (is_head ()) @@ -1057,9 +1064,6 @@ INVOKE_OBJECT (REMOVE, this); - if (object *pl = visible_to ()) - esrv_del_item (pl->contr, count); - flag [FLAG_REMOVED] = true; if (more) @@ -1071,6 +1075,11 @@ */ if (env) { + flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed + if (object *pl = visible_to ()) + esrv_del_item (pl->contr, count); + flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed + adjust_weight (env, -total_weight ()); *(above ? &above->below : &env->inv) = below; @@ -1098,20 +1107,30 @@ } else if (map) { - if (type == PLAYER) + map->dirty = true; + mapspace &ms = this->ms (); + + if (object *pl = ms.player ()) { - // leaving a spot always closes any open container on the ground - if (container && !container->env) - // this causes spurious floorbox updates, but it ensures - // that the CLOSE event is being sent. - close_container (); + if (type == PLAYER) // this == pl(!) + { + // leaving a spot always closes any open container on the ground + if (container && !container->env) + // this causes spurious floorbox updates, but it ensures + // that the CLOSE event is being sent. + close_container (); - --map->players; - map->touch (); - } + --map->players; + map->touch (); + } + else if (pl->container == this) + { + // removing a container should close it + close_container (); + } - map->dirty = true; - mapspace &ms = this->ms (); + esrv_del_item (pl->contr, count); + } /* link the object above us */ if (above) @@ -2611,7 +2630,9 @@ if (container == new_container) return; - if (object *old_container = container) + object *old_container = container; + + if (old_container) { if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) return; @@ -2623,10 +2644,15 @@ closer->destroy (); #endif + // make sure the container is available + esrv_send_item (this, old_container); + old_container->flag [FLAG_APPLIED] = false; container = 0; + // client needs item update to make it work, client bug requires this to be separate esrv_update_item (UPD_FLAGS, this, old_container); + new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); play_sound (sound_find ("chest_close")); } @@ -2649,13 +2675,19 @@ new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); + // make sure the container is available, client bug requires this to be separate + esrv_send_item (this, new_container); + new_container->flag [FLAG_APPLIED] = true; container = new_container; + // client needs flag change esrv_update_item (UPD_FLAGS, this, new_container); esrv_send_inventory (this, new_container); play_sound (sound_find ("chest_open")); } +// else if (!old_container->env && contr && contr->ns) +// contr->ns->floorbox_reset (); } object *