--- deliantra/server/common/object.C 2008/04/22 01:18:10 1.213 +++ deliantra/server/common/object.C 2008/04/22 07:01:46 1.214 @@ -332,6 +332,41 @@ return 1; } +// find player who can see this object +object * +object::visible_to () const +{ + if (!flag [FLAG_REMOVED]) + { + // see if we are in a container of sorts + if (env) + { + // the player inventory itself is always visible + if (env->type == PLAYER) + return env; + + // else a player could have our env open + object *envest = env->outer_env (); + + // the player itself is always on a map, so we will find him here + // even if our inv is in a player. + if (envest->is_on_map ()) + if (object *pl = envest->ms ().player ()) + if (pl->container == env) + return pl; + } + else + { + // 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; + } + } + + return 0; +} + // adjust weight per container type ("of holding") static sint32 weight_adjust (object *op, sint32 weight) @@ -1171,20 +1206,20 @@ ; for (; top; top = top->below) - { - if (top == op) - continue; + if (object::can_merge (op, top)) + { + top->nrof += op->nrof; - if (object::can_merge (op, top)) - { - top->nrof += op->nrof; + if (object *pl = top->visible_to ()) + esrv_update_item (UPD_NROF, pl, top); -/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ - op->weight = 0; /* Don't want any adjustements now */ - op->destroy (); - return top; - } - } + op->weight = 0; // cancel the addition above + op->carrying = 0; // must be 0 already + + op->destroy (1); + + return top; + } return 0; } @@ -1496,41 +1531,6 @@ return where->map->insert (this, where->x, where->y, originator, flags); } -// find player who can see this object -object * -object::visible_to () const -{ - if (!flag [FLAG_REMOVED]) - { - // see if we are in a container of sorts - if (env) - { - // the player inventory itself is always visible - if (env->type == PLAYER) - return env; - - // else a player could have our env open - object *envest = env->outer_env (); - - // the player itself is always on a map, so we will find him here - // even if our inv is in a player. - if (envest->is_on_map ()) - if (object *pl = envest->ms ().player ()) - if (pl->container == env) - return pl; - } - else - { - // 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; - } - } - - return 0; -} - /* * decrease(object, number) decreases a specified number from * the amount of an object. If the amount reaches 0, the object @@ -1640,6 +1640,10 @@ /* return the original object and remove inserted object (client needs the original object) */ tmp->nrof += op->nrof; + + if (object *pl = tmp->visible_to ()) + esrv_update_item (UPD_NROF, pl, tmp); + adjust_weight (this, op->total_weight ()); op->destroy (1); @@ -1663,6 +1667,9 @@ op->flag [FLAG_REMOVED] = 0; + if (object *pl = op->visible_to ()) + esrv_send_item (pl, op); + adjust_weight (this, op->total_weight ()); inserted: @@ -1670,9 +1677,9 @@ if (op->glow_radius && map && map->darkness) update_all_los (map, x, y); - if (object *otmp = in_player ()) - if (otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) - otmp->update_stats (); + // if this is a player's inventory, update stats + if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) + update_stats (); INVOKE_OBJECT (INSERT, this);