Пример #1
0
        public UInt32 ObjectAdd(ObjectAdd p)
        {
            var rezparams = new RezObjectParams();
            var group     = new Object.ObjectGroup();
            var part      = new ObjectPart();

            group.Add(1, part.ID, part);
            group.Name = "Primitive";
            IAgent agent      = Agents[p.AgentID];
            UGUI   agentOwner = agent.Owner;

            group.LastOwner        = agentOwner;
            part.Creator           = agentOwner;
            rezparams.RezzingAgent = agentOwner;
            ObjectPart.PrimitiveShape pshape = part.Shape;
            pshape.PCode            = p.PCode;
            part.Material           = p.Material;
            pshape.PathCurve        = p.PathCurve;
            pshape.ProfileCurve     = p.ProfileCurve;
            pshape.PathBegin        = p.PathBegin;
            pshape.PathEnd          = p.PathEnd;
            pshape.PathScaleX       = p.PathScaleX;
            pshape.PathScaleY       = p.PathScaleY;
            pshape.PathShearX       = p.PathShearX;
            pshape.PathShearY       = p.PathShearY;
            pshape.PathTwist        = p.PathTwist;
            pshape.PathTwistBegin   = p.PathTwistBegin;
            pshape.PathRadiusOffset = p.PathRadiusOffset;
            pshape.PathTaperX       = p.PathTaperX;
            pshape.PathTaperY       = p.PathTaperY;
            pshape.PathRevolutions  = p.PathRevolutions;
            pshape.PathSkew         = p.PathSkew;
            pshape.ProfileBegin     = p.ProfileBegin;
            pshape.ProfileEnd       = p.ProfileEnd;
            pshape.ProfileHollow    = p.ProfileHollow;

            rezparams.RayStart             = p.RayStart;
            rezparams.RayEnd               = p.RayEnd;
            rezparams.RayTargetID          = p.RayTargetID;
            rezparams.RayEndIsIntersection = p.RayEndIsIntersection;
            rezparams.Scale    = p.Scale;
            rezparams.Rotation = p.Rotation;
            pshape.State       = p.State;
            group.AttachPoint  = p.LastAttachPoint;

            part.Size          = Vector3.One / 2.0;
            part.BaseMask      = p.BasePermissions;
            part.EveryoneMask  = p.EveryOnePermissions;
            part.OwnerMask     = p.CurrentPermissions;
            part.NextOwnerMask = p.NextOwnerPermissions;
            part.GroupMask     = p.GroupPermissions;
            part.Shape         = pshape;
            group.Group.ID     = p.GroupID;
            part.ObjectGroup   = group;
            part.Size          = Vector3.One / 2f;

            /* initial setup of object */
            part.UpdateData(ObjectPartLocalizedInfo.UpdateDataFlags.All);

            var selectedList = agent.SelectedObjects(ID);

            foreach (UUID old in selectedList.GetAndClear())
            {
                ObjectPart oldSelectedPart;
                if (Primitives.TryGetValue(old, out oldSelectedPart))
                {
                    agent.ScheduleUpdate(oldSelectedPart.UpdateInfo, ID);
                }
            }
            selectedList.Add(part.ID);

            return(RezObject(group, rezparams));
        }
        public void HandleObjectDuplicate(Message m)
        {
            var req = (Viewer.Messages.Object.ObjectDuplicate)m;

            if (req.AgentID != m.CircuitAgentID ||
                req.SessionID != m.CircuitSessionID)
            {
                return;
            }

            IAgent agent;
            var    objectgroups = new List <ObjectGroup>();

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            bool isGod = agent.IsInScene(this) && agent.IsActiveGod;

            foreach (UInt32 localid in req.ObjectLocalIDs)
            {
                try
                {
                    ObjectGroup grp = Primitives[localid].ObjectGroup;
                    if (isGod || CanTakeCopy(agent, grp, grp.Position))
                    {
                        objectgroups.Add(grp);
                    }
                }
                catch
                {
                    agent.SendAlertMessage("ALERT: CantFindObject", ID);
                }
            }

            foreach (ObjectGroup grp in objectgroups)
            {
                var newgrp = new ObjectGroup(grp);
                foreach (ObjectPart part in grp.ValuesByKey1)
                {
                    var newpart = new ObjectPart(UUID.Random, part)
                    {
                        RezDate     = Date.Now,
                        ObjectGroup = newgrp
                    };
                    newgrp.Add(part.LinkNumber, newpart.ID, newpart);
                    newpart.UpdateData(ObjectPartLocalizedInfo.UpdateDataFlags.All);

                    foreach (KeyValuePair <UUID, ObjectPartInventoryItem> kvp in part.Inventory.Key1ValuePairs)
                    {
                        ScriptInstance instance = kvp.Value.ScriptInstance;
                        var            newItem  = new ObjectPartInventoryItem(UUID.Random, kvp.Value)
                        {
                            ExperienceID = kvp.Value.ExperienceID
                        };
                        if (instance != null)
                        {
                            try
                            {
                                newItem.ScriptState = instance.ScriptState;
                            }
                            catch
                            {
                                /* if taking script state fails, we do not bail out */
                            }
                        }
                        newpart.Inventory.Add(newItem);
                    }
                    newgrp.GlobalPosition   += req.Offset;
                    newpart.IsChangedEnabled = true;
                }

                UGI ugi = UGI.Unknown;
                GroupsNameService?.TryGetValue(req.GroupID, out ugi);
                newgrp.Group = ugi;
                newgrp.Owner = agent.Owner;

                RezObject(newgrp, grp.Owner);
#if DEBUG
                m_Log.DebugFormat("Duplicated object {0} ({1}, {2}) as {3} ({4}, {5})", grp.Name, grp.LocalID, grp.ID, newgrp.Name, newgrp.LocalID, newgrp.ID);
#endif
            }
        }