Inheritance: Universe.Framework.Modules.IDataTransferable
        public override void FromOSD(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse(args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["far"] != null)
                Far = (float) (args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float) args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float) (args["energy_level"].AsReal());

            //This IS checked later
            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["speed"] != null)
                float.TryParse(args["speed"].AsString(), out Speed);
            else
                Speed = 1;

            if (args["draw_distance"] != null)
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            else
                DrawDistance = 0;

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
                Speed = 1;

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            SentInitialWearables = args["sent_initial_wearables"] != null && args["sent_initial_wearables"].AsBoolean();

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if (args["IsCrossing"] != null)
                IsCrossing = args["IsCrossing"].AsBoolean();

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray) (args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;

                foreach (OSD o in anims.Where(o => o.Type == OSDType.Map))
                {
                    Anims[i++] = new Animation((OSDMap) o);
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                    Appearance = new AvatarAppearance(AgentID, (OSDMap) args["packed_appearance"]);
                    // DEBUG ON
                else
                    MainConsole.Instance.Warn("[CHILDAGENTDATAUPDATE] No packed appearance");
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray) (args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;

                foreach (OSD o in controls.Where(o => o.Type == OSDType.Map))
                {
                    Controllers[i++] = new ControllerData((OSDMap) o);
                }
            }

            if (args["SittingObjects"] != null && args["SittingObjects"].Type == OSDType.Map)
                SittingObjects = new SittingObjectData((OSDMap) args["SittingObjects"]);
        }
Example #2
0
        public override void FromOSD(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse(args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            //This IS checked later
            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["speed"] != null)
            {
                float.TryParse(args["speed"].AsString(), out Speed);
            }
            else
            {
                Speed = 1;
            }

            if (args["draw_distance"] != null)
            {
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            }
            else
            {
                DrawDistance = 0;
            }

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
            {
                Speed = 1;
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            SentInitialWearables = args["sent_initial_wearables"] != null && args["sent_initial_wearables"].AsBoolean();

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if (args["IsCrossing"] != null)
            {
                IsCrossing = args["IsCrossing"].AsBoolean();
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;

                foreach (OSD o in anims.Where(o => o.Type == OSDType.Map))
                {
                    Anims[i++] = new Animation((OSDMap)o);
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                {
                    Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
                }
                // DEBUG ON
                else
                {
                    MainConsole.Instance.Warn("[CHILDAGENTDATAUPDATE] No packed appearance");
                }
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;

                foreach (OSD o in controls.Where(o => o.Type == OSDType.Map))
                {
                    Controllers[i++] = new ControllerData((OSDMap)o);
                }
            }

            if (args["SittingObjects"] != null && args["SittingObjects"].Type == OSDType.Map)
            {
                SittingObjects = new SittingObjectData((OSDMap)args["SittingObjects"]);
            }
        }
        public void SitOnObjectAfterCrossing(SittingObjectData sod)
        {
            UUID targetID = sod.m_objectID;

            ISceneChildEntity part = FindNextAvailableSitTarget(targetID);
            if (part == null)
                return;

            if (string.IsNullOrEmpty(sod.m_animation))
                m_nextSitAnimation = "SIT";

            m_requestedSitTargetUUID = targetID;
            m_sitting = true;

            Vector3 sitTargetPos = sod.m_sitTargetPos;
            Quaternion sitTargetOrient = sod.m_sitTargetRot;

            m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
            //m_pos += SIT_TARGET_ADJUSTMENT;
            m_bodyRot = sitTargetOrient;
            m_parentPosition = part.AbsolutePosition;
            m_parentID = m_requestedSitTargetUUID;

            part.SitTargetAvatar.Add(UUID);
            Velocity = Vector3.Zero;
            RemoveFromPhysicalScene();

            //Send updates to everyone about us
            foreach (IScenePresence sp in m_scene.GetScenePresences())
            {
                sp.SceneViewer.QueuePresenceForFullUpdate(this, true);
            }
            Animator.TrySetMovementAnimation(m_nextSitAnimation);
        }
        public virtual void CopyFrom(AgentData cAgent)
        {
            try
            {
                m_pos = cAgent.Position;
                if (PhysicsActor != null)
                {
                    AbsolutePosition = cAgent.Position;
                    PhysicsActor.ForceSetPosition(cAgent.Position);
                }
                Velocity = cAgent.Velocity;
                m_CameraCenter = cAgent.Center;
                SetHeight(cAgent.Size.Z);
                m_CameraAtAxis = cAgent.AtAxis;
                m_CameraLeftAxis = cAgent.LeftAxis;
                m_CameraUpAxis = cAgent.UpAxis;

                DrawDistance = cAgent.Far;

                if ((cAgent.Throttles != null) && cAgent.Throttles.Length > 0)
                    ControllingClient.SetChildAgentThrottle(cAgent.Throttles);

                m_headrotation = cAgent.HeadRotation;
                m_bodyRot = cAgent.BodyRotation;
                m_AgentControlFlags = (AgentManager.ControlFlags) cAgent.ControlFlags;
                m_savedVelocity = cAgent.Velocity;

                SpeedModifier = cAgent.Speed;
                DrawDistance = cAgent.DrawDistance;
                m_setAlwaysRun = cAgent.AlwaysRun;
                if (cAgent.IsCrossing)
                {
                    m_scene.AuthenticateHandler.GetAgentCircuitData(UUID).TeleportFlags |=
                        (uint) TeleportFlags.ViaRegionID;
                    m_scene.AuthenticateHandler.GetAgentCircuitData(UUID).IsChildAgent = false;
                        //We're going to be a root
                }
                IAvatarAppearanceModule appearance = RequestModuleInterface<IAvatarAppearanceModule>();
                if (appearance != null)
                {
                    appearance.InitialHasWearablesBeenSent = cAgent.SentInitialWearables;
                    appearance.Appearance = new AvatarAppearance(cAgent.Appearance);
                }

                // Animations
                try
                {
                    Animator.ResetAnimations();
                    Animator.Animations.FromArray(cAgent.Anims);
                }
                catch
                {
                }
                try
                {
                    if (cAgent.SittingObjects != null && cAgent.SittingObjects.m_sittingObjectXML != "")
                    {
                        ISceneEntity sceneObject = null;
                        IRegionSerializerModule mod = Scene.RequestModuleInterface<IRegionSerializerModule>();
                        if (mod != null)
                            sceneObject = mod.DeserializeGroupFromXml2(cAgent.SittingObjects.m_sittingObjectXML, Scene);

                        if (sceneObject != null)
                        {
                            //We were sitting on something when we crossed
                            if (Scene.SceneGraph.RestorePrimToScene(sceneObject, false))
                            {
                                if (sceneObject.IsSelected)
                                    sceneObject.RootChild.CreateSelected = true;
                                sceneObject.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
                                sceneObject.CreateScriptInstances(0, false, StateSource.PrimCrossing, UUID.Zero, false);

                                sceneObject.RootChild.PhysActor.ForceSetVelocity(cAgent.Velocity);
                                sceneObject.RootChild.PhysActor.Velocity = (cAgent.Velocity);
                                sceneObject.AbsolutePosition = cAgent.Position;
                                Animator.TrySetMovementAnimation(cAgent.SittingObjects.m_animation);
                                m_nextSitAnimation = cAgent.SittingObjects.m_animation;
                                cAgent.SittingObjects.m_objectID = sceneObject.UUID;
                                m_objectToSitOn = cAgent.SittingObjects;

                                foreach (ISceneChildEntity child in sceneObject.ChildrenEntities())
                                {
                                    foreach (TaskInventoryItem taskInv in child.Inventory.GetInventoryItems())
                                    {
                                        foreach (ControllerData cd in cAgent.Controllers)
                                        {
                                            if (cd.ItemID == taskInv.ItemID || cd.ItemID == taskInv.OldItemID)
                                            {
                                                cd.ItemID = taskInv.ItemID;
                                            }
                                        }
                                    }
                                }

                                try
                                {
                                    IScriptControllerModule m = RequestModuleInterface<IScriptControllerModule>();
                                    if (m != null)
                                        if (cAgent.Controllers != null)
                                            m.Deserialize(cAgent.Controllers);
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[Scene presence]: Error in CopyFrom: " + ex);
            }
        }
        /// <summary>
        ///     Complete Avatar's movement into the region.
        ///     This is called upon a very important packet sent from the client,
        ///     so it's client-controlled. Never call this method directly.
        /// </summary>
        private void CompleteMovement(IClientAPI client)
        {
            //MainConsole.Instance.Debug("[SCENE PRESENCE]: CompleteMovement for " + Name + " in " + m_regionInfo.RegionName);

            string reason = "";
            Vector3 pos;
            //Get a good position and make sure that we exist in the grid
            AgentCircuitData agent = m_scene.AuthenticateHandler.GetAgentCircuitData(UUID);

            if (agent == null ||
                !Scene.Permissions.AllowedIncomingTeleport(UUID, AbsolutePosition, agent.TeleportFlags, out pos,
                                                           out reason))
            {
                MainConsole.Instance.Error("[ScenePresence]: Error in MakeRootAgent! Could not authorize agent " + Name +
                                           ", reason: " + reason);
                return;
            }

            bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
            MakeRootAgent(pos, m_flying, m_objectToSitOn == null);
            Animator.NeedsAnimationResent = true;

            if (m_objectToSitOn != null)
            {
                SitOnObjectAfterCrossing(m_objectToSitOn);
                m_objectToSitOn = null;
            }
        }