Esempio n. 1
0
        /// <summary>
        ///   Deserialization of agent data.
        ///   Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name = "hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            // DEBUG ON
            //MainConsole.Instance.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            // DEBUG OFF

            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["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            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;
#if (!ISWIN)
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
#else
                foreach (OSD o in anims.Where(o => o.Type == OSDType.Map))
                {
                    Anims[i++] = new Animation((OSDMap)o);
                }
#endif
            }

            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.WarnFormat("[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;
#if (!ISWIN)
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
#else
                foreach (OSD o in controls.Where(o => o.Type == OSDType.Map))
                {
                    Controllers[i++] = new ControllerData((OSDMap)o);
                }
#endif
            }

            if (args["SittingObjects"] != null && args["SittingObjects"].Type == OSDType.Map)
            {
                SittingObjects = new SittingObjectData((OSDMap)args["SittingObjects"]);
            }
        }