コード例 #1
0
        private void PlaySound(SoundResource sound)
        {
            // Adjust the sound back to normal settings if it is a looping sound that is already playing
            if ((currentPlayHandle != null) && currentPlayHandle.IsPlaying() && Looping)
            {
                AdjustSound(Loudness, PitchOffset);
                return;
            }

            StopSound(false);

            PlaySettings playSettings = (Looping ? PlaySettings.Looped : PlaySettings.PlayOnce);

            playSettings.DontSync   = false;
            playSettings.Loudness   = LoudnessPercentToDb(Loudness + LoudnessVariance * RandomNegOneToOne());
            playSettings.PitchShift = PitchOffset + PitchVariance * RandomNegOneToOne();

            if (Spatialized)
            {
                if (audio != null)
                {
                    currentPlayHandle = audio.PlaySoundOnComponent(sound, playSettings);
                }
                else
                {
                    currentPlayHandle = ScenePrivate.PlaySoundAtPosition(sound, ObjectPrivate.Position, playSettings);
                }
            }
            else
            {
                currentPlayHandle = ScenePrivate.PlaySound(sound, playSettings);
            }
        }
コード例 #2
0
        public void fireRez(Sansar.Vector position, Sansar.Vector fwd, Sansar.Quaternion orientation)
        {
            Sansar.Vector rezPosition;
            if (Sound_To_Play != null)
            {
                ScenePrivate.PlaySoundAtPosition(Sound_To_Play, position, PlaySettings.PlayOnce);
            }
            for (int i = 0; i < numberOfRez; i++)
            {
                //so i starts at 0, and will eventually be spacing away, if we add .5 that means .5 of fwd which means if the object is centered
                //it will come right out of our av, .6 is 10% more so we dont hit ourself
                rezPosition = position + offset +
                              (
                    fwd * (spacing * (i + .6f))
                              );

                ScenePrivate.CreateCluster(
                    Bullet_Object,
                    rezPosition,
                    orientation,
                    Sansar.Vector.Zero,
                    CreateClusterHandler
                    );
                Wait(TimeSpan.FromSeconds(.1));
            }
        }
コード例 #3
0
 public int Hit(AgentInfo agent, ScenePrivate scene)
 {
     if (HitSound != null)
     {
         scene.PlaySoundAtPosition(HitSound, ObjectPrivate.Position, SoundSettings);
     }
     return(PointValue);
 }
コード例 #4
0
 void Reload(CommandData command)
 {
     try
     {
         if (ReloadedSound != null)
         {
             ScenePrivate.PlaySoundAtPosition(ReloadedSound, command.TargetingOrigin, ShotSettings);
         }
         if (DebugLogging)
         {
             Log.Write(GetType().Name, "Reloaded");
         }
         ammo = ClipSize;
     }
     catch (System.Exception) { }
 }
コード例 #5
0
        void OnBan(CommandData command)
        {
            try {
                if (command.ControlPoint != heldHand && command.ControlPoint != ControlPointType.DesktopGrab && heldHand != ControlPointType.DesktopGrab)
                {
                    return;
                }

                var targetAgent = ScenePrivate.FindAgent(command.TargetingComponent.ObjectId);
                if (targetAgent != null)
                {
                    string banButton = EnableCheese ? "Ban Ban!" : "Ban";
                    WaitFor(holdingAgent.Client.UI.ModalDialog.Show, "Would you like to ban " + targetAgent.AgentInfo.Name + " (" + targetAgent.AgentInfo.Handle.ToLower() + ") from this scene for " + BanDuration + " minutes?", banButton, EnableCheese ? "Never mind..." : "Cancel");
                    if (holdingAgent.Client.UI.ModalDialog.Response == banButton)
                    {
                        Bannish(targetAgent);
                        Banned[targetAgent.AgentInfo.Handle.ToLower()] = Stopwatch.GetTimestamp() + TimeSpan.FromMinutes(BanDuration).Ticks;
                        if (EnableCheese)
                        {
                            ScenePrivate.Chat.MessageAllUsers("HEY " + targetAgent.AgentInfo.Name + "! " + cheese[rnd.Next(cheese.Count)]);
                        }
                        if (UserEjectedSound != null)
                        {
                            ScenePrivate.PlaySoundAtPosition(UserEjectedSound, command.TargetingPosition, SoundSettings);
                        }
                    }
                }
                else if (FailedSelectionSound != null)
                {
                    ScenePrivate.PlaySoundAtPosition(FailedSelectionSound, command.TargetingOrigin, SoundSettings);
                }
            }
            catch (NullReferenceException nre) { if (DebugSpam)
                                                 {
                                                     Log.Write("OnBan", nre.Message);
                                                 }
            }
            catch (Exception e) { if (DebugSpam)
                                  {
                                      Log.Write("OnBan", e.ToString());
                                  }
            }                                                                       // ignore exceptions for not found agents.
        }
コード例 #6
0
 public int Hit(AgentInfo agent, ScenePrivate scene)
 {
     if (HitSound != null)
     {
         scene.PlaySoundAtPosition(HitSound, ObjectPrivate.Position, SoundSettings);
     }
     try
     {
         SimpleData simpleData = new SimpleData(this);
         simpleData.AgentInfo      = agent;
         simpleData.ObjectId       = agent.ObjectId;
         simpleData.SourceObjectId = ObjectPrivate.ObjectId;
         PostScriptEvent(ShotHitEvent, simpleData);
         if (DebugLogging)
         {
             Log.Write("Event sent  ", ShotHitEvent);
         }
     }
     catch (System.Exception) { }
     return(PointValue);
 }
コード例 #7
0
 void OnPickup(HeldObjectData data)
 {
     try {
         unsubscribe?.Invoke();
         unsubscribe  = null;
         holdingAgent = ScenePrivate.FindAgent(data.HeldObjectInfo.SessionId);
         if (IsAdmin(holdingAgent))
         {
             heldHand     = data.HeldObjectInfo.ControlPoint;
             unsubscribe  = holdingAgent.Client.SubscribeToCommand(BanCommand, OnBan, null).Unsubscribe;
             unsubscribe += holdingAgent.Client.SubscribeToCommand(InfoCommand, OnInfo, null).Unsubscribe;
         }
         else
         {
             if (UnauthorizedSound != null)
             {
                 ScenePrivate.PlaySoundAtPosition(UnauthorizedSound, ScenePrivate.FindObject(holdingAgent.AgentInfo.ObjectId).Position, SoundSettings);
             }
             holdingAgent.Client.UI.ModalDialog.Show("This tool is only usable by designated users. Not you.\nPlease drop the tool or you will be forced to drop it.", "Ok", "");
             AgentPrivate invalidUser = holdingAgent;
             Timer.Create(TimeSpan.FromSeconds(60), () => { if (holdingAgent == invalidUser)
                                                            {
                                                                Bannish(holdingAgent, ScenePrivate.SceneInfo.SansarUri);
                                                            }
                          });
         }
         unsubscribe += () => { unsubscribe = null; holdingAgent = null; };
     }
     catch (NullReferenceException nre) { if (DebugSpam)
                                          {
                                              Log.Write("OnPickup", nre.Message);
                                          }
     }                                                                                         // ignore exceptions for not found agents.
     catch (Exception e) { if (DebugSpam)
                           {
                               Log.Write("OnPickup", e.ToString());
                           }
                           holdingAgent = null; }
 }
コード例 #8
0
    public void OnFire(AnimationComponent animationComponent)
    {
        if (RezThrottled == true)
        {   // TODO: Play a "click" / misfire sound.
            return;
        }

        ObjectPrivate characterObject = ScenePrivate.FindObject(animationComponent.ComponentId.ObjectId);

        if (Fire_Sound != null)
        {
            ScenePrivate.PlaySoundAtPosition(Fire_Sound, characterObject.Position, SoundSettings);
        }

        Sansar.Vector cameraForward = animationComponent.GetVectorAnimationVariable("LLCameraForward");
        cameraForward.W = 0.0f;
        cameraForward   = cameraForward.Normalized();

        Sansar.Vector offset = new Sansar.Vector(cameraForward[0], cameraForward[1], 0, 0).Normalized();

        Sansar.Vector new_pos = new Sansar.Vector(0f, 0f, 1.5f, 0f);
        new_pos += characterObject.Position; // This script is on the Avatar, so the Avatar is the owning object.
        new_pos += (offset * 0.6f);          // Add to the world just in front of the avatar.

        float speed = InitialSpeed;

        if (InitialSpeed < 1.0f || InitialSpeed > 200.0f)
        {
            const float defaultSpeed = 10.0f;
            Log.Write(string.Format("Bad CannonBall Speed: {0}, using default {1}", InitialSpeed, defaultSpeed));
            speed = defaultSpeed;
        }

        Sansar.Vector vel = cameraForward * speed;

        StartCoroutine(RezCannonball, new_pos, Quaternion.FromLook(cameraForward, Vector.Up), vel);

        Timer.Create(TimeSpan.FromSeconds(Delay), () => { animationComponent.Subscribe(ListenEvent, (data) => { OnFire(animationComponent); }, false); });
    }
コード例 #9
0
        void OnTrigger(CommandData command)
        {
            try
            {
                if (CheckReload(command))
                {
                    return;
                }

                if (command.ControlPoint != heldHand)
                {
                    // Let them use the off hand to reload the gun, but otherwise early exit.
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, $"Dropping Non-reload from device {command.ControlPoint.ToString()} while being held by {command.ControlPoint.ToString()}");
                    }
                    return;
                }

                if (ammo <= 0)
                {
                    // Play 'empty' sound
                    if (OutOfAmmoSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(OutOfAmmoSound, command.TargetingOrigin, ShotSettings);
                    }
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, "Out of ammo");
                    }
                    return;
                }


                shotsFired++;
                ammo--;

                var targetAgent = ScenePrivate.FindAgent(command.TargetingComponent.ObjectId);
                if (targetAgent != null)
                {
                    shotsHit++;
                    score += PointsPerPlayer;
                    if (PlayerHitSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(PlayerHitSound, command.TargetingPosition, TargetSettings);
                    }
                    if (ShotHitSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(ShotHitSound, command.TargetingOrigin, ShotSettings);
                    }
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, "Player Hit");
                    }
                }
                else
                {
                    ObjectPrivate targetObject = ScenePrivate.FindObject(command.TargetingComponent.ObjectId);
                    if (targetObject != null)
                    {
                        Target target = targetObject.FindScripts <Target>("PewPewExample.Target").FirstOrDefault();
                        if (target != null)
                        {
                            if (ShotHitSound != null)
                            {
                                ScenePrivate.PlaySoundAtPosition(ShotHitSound, command.TargetingOrigin, ShotSettings);
                            }
                            if (DebugLogging)
                            {
                                Log.Write(GetType().Name, "Target hit");
                            }
                            score += target.Hit(holdingAgent, ScenePrivate);
                            shotsHit++;
                            return;
                        }
                    }
                    if (ShotMissSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(ShotMissSound, command.TargetingOrigin, ShotSettings);
                    }
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, "Miss:: " + command.ToString());
                    }
                }
            }
            catch (System.Exception) { } // ignore exceptions for not found agents.
        }
コード例 #10
0
    public void RezCannonball(Sansar.Vector initial_pos, Sansar.Quaternion rotation, Sansar.Vector vel)
    {
        ScenePrivate.CreateClusterData createData = null;
        try
        {
            try
            {
                if (Projectile != null)
                {
                    createData = (ScenePrivate.CreateClusterData)WaitFor(ScenePrivate.CreateCluster, Projectile,
                                                                         initial_pos,
                                                                         rotation,
                                                                         vel);
                }
                else
                {   // No projectile override - just use cannon balls.
                    createData = (ScenePrivate.CreateClusterData)WaitFor(ScenePrivate.CreateCluster, "Export/CannonBall/",
                                                                         initial_pos,
                                                                         rotation,
                                                                         vel);
                }
            }
            catch (ThrottleException e)
            {
                Log.Write($"Too many rezzes! Throttle rate is {e.MaxEvents} per {e.Interval.TotalSeconds}.");
                RezThrottled = true;
                Wait(e.Interval - e.Elapsed); // Wait out the rest of the interval before trying again.
                RezThrottled = false;
                return;
            }

            if (createData.Success)
            {
                ObjectPrivate obj = createData.ClusterReference.GetObjectPrivate(0);
                if (obj != null)
                {
                    RigidBodyComponent RigidBody = null;
                    if (obj.TryGetFirstComponent(out RigidBody))
                    {
                        //exit after 3 hits or 1 character hit
                        for (int i = 0; i < 3; i++)
                        {
                            CollisionData data = (CollisionData)WaitFor(RigidBody.Subscribe, CollisionEventType.AllCollisions, ComponentId.Invalid);

                            if ((data.EventType & CollisionEventType.CharacterContact) != 0)
                            {
                                // Use the scene to find the full object API of the other object.
                                AgentPrivate hit = ScenePrivate.FindAgent(data.HitComponentId.ObjectId);
                                if (hit != null)
                                {
                                    ObjectPrivate otherObject = ScenePrivate.FindObject(data.HitComponentId.ObjectId);
                                    if (otherObject != null)
                                    {
                                        if (Hit_Sound != null)
                                        {
                                            ScenePrivate.PlaySoundAtPosition(Hit_Sound, otherObject.Position, SoundSettings);
                                        }

                                        if (Teleport_On_Hit)
                                        {
                                            AnimationComponent anim;
                                            if (otherObject.TryGetFirstComponent(out anim))
                                            {
                                                anim.SetPosition(SpawnPoints[rng.Next(SpawnPoints.Count)]);
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            Log.Write(e.ToString());
        }
        finally
        {
            if (createData.ClusterReference != null)
            {
                try
                {
                    createData.ClusterReference.Destroy();
                }
                catch (Exception) { }
            }
        }
    }
コード例 #11
0
        void OnTrigger(CommandData command)
        {
            if (command.ControlPoint == ControlPointType.DesktopGrab)
            {
                if (!FreeClickEnabled && !command.MouseLookMode)
                {
                    AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                    user.SendChat("This device does not work in desktop Free Click Mode: press Escape to enter or exit Mouse Look.");
                    return;
                }
            }

            try
            {
                if (CheckReload(command))
                {
                    return;
                }

                if (command.ControlPoint != heldHand)
                {
                    // Let them use the off hand to reload the gun, but otherwise early exit.
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, $"Dropping Non-reload from device {command.ControlPoint.ToString()} while being held by {command.ControlPoint.ToString()}");
                    }
                    return;
                }

                if (ClipSize > 0 && ammo <= 0)
                {
                    // Play 'empty' sound
                    if (OutOfAmmoSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(OutOfAmmoSound, command.TargetingOrigin, ShotSettings);
                    }
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, "Out of ammo");
                    }
                    return;
                }


                shotsFired++;
                ammo--;
                if (ShotSound != null)
                {
                    ScenePrivate.PlaySoundAtPosition(ShotSound, command.TargetingOrigin, ShotSettings);
                }


                var targetAgent = ScenePrivate.FindAgent(command.TargetingComponent.ObjectId);
                if (targetAgent != null)
                {
                    shotsHit++;
                    score += PointsPerPlayer;
                    if (PlayerHitSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(PlayerHitSound, command.TargetingPosition, TargetSettings);
                    }
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, "Player Hit");
                    }
                }
                else
                {
                    ObjectPrivate targetObject = ScenePrivate.FindObject(command.TargetingComponent.ObjectId);
                    if (targetObject != null)
                    {
                        Target target = targetObject.FindScripts <Target>("PewPewExample.Target").FirstOrDefault();
                        if (target != null)
                        {
                            if (DebugLogging)
                            {
                                Log.Write(GetType().Name, "Target hit");
                            }
                            score += target.Hit(holdingAgent, ScenePrivate);
                            shotsHit++;
                            return;
                        }
                    }
                    if (ShotMissSound != null)
                    {
                        ScenePrivate.PlaySoundAtPosition(ShotMissSound, command.TargetingOrigin, ShotSettings);
                    }
                    if (DebugLogging)
                    {
                        Log.Write(GetType().Name, "Miss:: " + command.ToString());
                    }
                }
            }
            catch (System.Exception) { } // ignore exceptions for not found agents.
        }