Exemplo n.º 1
0
        public void llPursue(LSL_String target, LSL_List options)
        {
            IBotManager botManager = World.RequestModuleInterface <IBotManager>();

            if (botManager != null)
            {
                float   fuzz       = 2;
                Vector3 offset     = Vector3.Zero;
                bool    requireLOS = false;
                // 20131224 not used                bool intercept;  = false; //Not implemented
                for (int i = 0; i < options.Length; i += 2)
                {
                    LSL_Integer opt = options.GetLSLIntegerItem(i);
                    if (opt == ScriptBaseClass.PURSUIT_FUZZ_FACTOR)
                    {
                        fuzz = (float)options.GetLSLFloatItem(i + 1).value;
                    }
                    if (opt == ScriptBaseClass.PURSUIT_OFFSET)
                    {
                        offset = options.GetVector3Item(i + 1).ToVector3();
                    }
                    if (opt == ScriptBaseClass.REQUIRE_LINE_OF_SIGHT)
                    {
                        requireLOS = options.GetLSLIntegerItem(i + 1) == 1;
                    }
                    // 20131224 not used                    if (opt == ScriptBaseClass.PURSUIT_INTERCEPT)
                    // 20131224 not used                        intercept = options.GetLSLIntegerItem(i + 1) == 1;
                }
                botManager.FollowAvatar(m_host.ParentEntity.UUID, target.m_string, fuzz, fuzz, requireLOS, offset,
                                        m_host.ParentEntity.OwnerID);
            }
        }
Exemplo n.º 2
0
        public void botSetMap(string keyOfBot, LSL_List positions, LSL_List movementType, LSL_Integer flags)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botSetMap", m_host, "bot", m_itemID))
            {
                return;
            }
            List <Vector3> PositionsMap = new List <Vector3>();

            for (int i = 0; i < positions.Length; i++)
            {
                LSL_Vector pos = positions.GetVector3Item(i);
                PositionsMap.Add(new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
            }
            List <TravelMode> TravelMap = new List <TravelMode>();

            for (int i = 0; i < movementType.Length; i++)
            {
                LSL_Integer travel = movementType.GetLSLIntegerItem(i);
                TravelMap.Add((TravelMode)travel.value);
            }

            IBotManager manager = World.RequestModuleInterface <IBotManager>();

            if (manager != null)
            {
                manager.SetBotMap(UUID.Parse(keyOfBot), PositionsMap, TravelMap, flags.value, m_host.OwnerID);
            }
        }
Exemplo n.º 3
0
        public void llNavigateTo(LSL_Vector point, LSL_List options)
        {
            List <Vector3> positions = new List <Vector3>()
            {
                point.ToVector3()
            };
            List <TravelMode> travelMode = new List <TravelMode>()
            {
                TravelMode.Walk
            };
            IBotManager botManager = World.RequestModuleInterface <IBotManager>();
            int         flags      = 0;

            if (options.Length > 0)
            {
                flags |= options.GetLSLIntegerItem(0);
            }
            if (botManager != null)
            {
                botManager.SetBotMap(m_host.ParentEntity.UUID, positions, travelMode, flags, m_host.ParentEntity.OwnerID);
            }
        }
Exemplo n.º 4
0
        public void llSetKeyframedMotion(LSL_List keyframes, LSL_List options)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
            {
                return;
            }
            if (!m_host.IsRoot)
            {
                Error("llSetKeyframedMotion", "Must be used in the root object!");
                return;
            }
            KeyframeAnimation.Data  dataType    = KeyframeAnimation.Data.Both;
            KeyframeAnimation.Modes currentMode = KeyframeAnimation.Modes.Forward;
            for (int i = 0; i < options.Length; i += 2)
            {
                LSL_Integer option = options.GetLSLIntegerItem(i);
                LSL_Integer value  = options.GetLSLIntegerItem(i + 1);
                if (option == ScriptBaseClass.KFM_COMMAND)
                {
                    m_host.ParentEntity.AddKeyframedMotion(null, (KeyframeAnimation.Commands)value.value);
                    break; //Its supposed to be the only option in the list
                }
                if (option == ScriptBaseClass.KFM_MODE)
                {
                    currentMode = (KeyframeAnimation.Modes)value.value;
                }
                else if (option == ScriptBaseClass.KFM_DATA)
                {
                    dataType = (KeyframeAnimation.Data)value.value;
                }
            }
            List <Vector3>    positions = new List <Vector3>();
            List <Quaternion> rotations = new List <Quaternion>();
            List <float>      times     = new List <float>();

            for (int i = 0; i < keyframes.Length; i += (dataType == KeyframeAnimation.Data.Both ? 3 : 2))
            {
                if (dataType == KeyframeAnimation.Data.Both ||
                    dataType == KeyframeAnimation.Data.Translation)
                {
                    LSL_Vector pos = keyframes.GetVector3Item(i);
                    positions.Add(pos.ToVector3());
                }
                if (dataType == KeyframeAnimation.Data.Both ||
                    dataType == KeyframeAnimation.Data.Rotation)
                {
                    LSL_Rotation rot  = keyframes.GetQuaternionItem(i + (dataType == KeyframeAnimation.Data.Both ? 1 : 0));
                    Quaternion   quat = rot.ToQuaternion();
                    quat.Normalize();
                    rotations.Add(quat);
                }
                LSL_Float time = keyframes.GetLSLFloatItem(i + (dataType == KeyframeAnimation.Data.Both ? 2 : 1));
                times.Add((float)time);
            }
            KeyframeAnimation animation = new KeyframeAnimation
            {
                CurrentMode              = currentMode,
                PositionList             = positions.ToArray(),
                RotationList             = rotations.ToArray(),
                TimeList                 = times.ToArray(),
                CurrentAnimationPosition = 0,
                InitialPosition          = m_host.AbsolutePosition,
                InitialRotation          = m_host.GetRotationOffset()
            };

            m_host.ParentEntity.AddKeyframedMotion(animation, KeyframeAnimation.Commands.Play);
        }
Exemplo n.º 5
0
        public void llUpdateCharacter(LSL_List options)
        {
            IBotManager botManager = World.RequestModuleInterface <IBotManager>();

            if (botManager != null)
            {
                IBotController controller = botManager.GetCharacterManager(m_host.ParentEntity.UUID);
                if (controller == null)
                {
                    return;         // nothing to controll :(
                }
                for (int i = 0; i < options.Length; i += 2)
                {
                    LSL_Integer opt   = options.GetLSLIntegerItem(i);
                    LSL_Float   value = options.GetLSLFloatItem(i + 1);
                    if (opt == ScriptBaseClass.CHARACTER_DESIRED_SPEED)
                    {
                        controller.SetSpeedModifier((float)value.value);
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_RADIUS)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_LENGTH)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_ORIENTATION)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_AVOIDANCE_MODE)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_TYPE)
                    {
                    }
                    else if (opt == ScriptBaseClass.TRAVERSAL_TYPE)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_MAX_ACCEL)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_MAX_DECEL)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_MAX_TURN_RADIUS)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_DESIRED_TURN_SPEED)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_MAX_SPEED)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_ACCOUNT_FOR_SKIPPED_FRAMES)
                    {
                    }
                    else if (opt == ScriptBaseClass.CHARACTER_STAY_WITHIN_PARCEL)
                    {
                    }
                }
            }
        }
        public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
            {
                return(new LSL_List());
            }

            LSL_List list = new LSL_List();

            Vector3 rayStart = start.ToVector3();
            Vector3 rayEnd   = end.ToVector3();
            Vector3 dir      = rayEnd - rayStart;

            float dist = Vector3.Mag(dir);

            int  count         = 1;
            bool detectPhantom = false;
            int  dataFlags     = 0;
            int  rejectTypes   = 0;

            for (int i = 0; i < options.Length; i += 2)
            {
                if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
                {
                    count = options.GetLSLIntegerItem(i + 1);
                }
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
                {
                    detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
                }
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
                {
                    dataFlags = options.GetLSLIntegerItem(i + 1);
                }
                else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
                {
                    rejectTypes = options.GetLSLIntegerItem(i + 1);
                }
            }

            if (count > 16)
            {
                count = 16;
            }
            else if (count <= 0)
            {
                Error("llCastRay", "You must request at least one result from llCastRay.");
                return(new LSL_List());
            }

            List <ContactResult> results = new List <ContactResult>();

            bool checkTerrain     = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
            bool checkAgents      = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
            bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
            bool checkPhysical    = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);


            if (checkAgents)
            {
                ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
                foreach (ContactResult r in agentHits)
                {
                    results.Add(r);
                }
            }

            if (checkPhysical || checkNonPhysical || detectPhantom)
            {
                ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom, count + 2);
                for (int iter = 0; iter < objectHits.Length; iter++)
                {
                    // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
                    objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
                    results.Add(objectHits[iter]);
                }
            }

            if (checkTerrain)
            {
                ContactResult?groundContact = GroundIntersection(rayStart, rayEnd);
                if (groundContact != null)
                {
                    results.Add((ContactResult)groundContact);
                }
            }

            results.Sort(delegate(ContactResult a, ContactResult b) {
                return(a.Depth.CompareTo(b.Depth));
            });

            int          values  = 0;
            ISceneEntity thisgrp = m_host.ParentEntity;

            foreach (ContactResult result in results)
            {
                if (result.Depth > dist)
                {
                    continue;
                }

                // physics ray can return colisions with host prim
                // this is supposed to happen
                if (m_host.LocalId == result.ConsumerID)
                {
                    continue;
                }

                if (!checkTerrain && result.ConsumerID == 0)
                {
                    continue; //Terrain
                }
                UUID itemID  = UUID.Zero;
                int  linkNum = 0;

                ISceneChildEntity part = World.GetSceneObjectPart(result.ConsumerID);
                // It's a prim!
                if (part != null)
                {
                    // dont detect members of same object ???
                    if (part.ParentEntity == thisgrp)
                    {
                        continue;
                    }

                    if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
                    {
                        itemID = part.ParentEntity.UUID;
                    }
                    else
                    {
                        itemID = part.UUID;
                    }

                    linkNum = part.LinkNum;
                }
                else
                {
                    IScenePresence sp = World.GetScenePresence(result.ConsumerID);
                    /// It it a boy? a girl?
                    if (sp != null)
                    {
                        itemID = sp.UUID;
                    }
                }

                list.Add(new LSL_String(itemID.ToString()));

                if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
                {
                    list.Add(new LSL_Integer(linkNum));
                }

                list.Add(new LSL_Vector(result.Pos));

                if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
                {
                    Vector3 norm = result.Normal * -1;
                    list.Add(new LSL_Vector(norm));
                }

                values++;
                if (values >= count)
                {
                    break;
                }
            }

            list.Add(new LSL_Integer(values));

            return(list);
        }