Esempio n. 1
0
        protected override string ReflectiveName => "Simple.Target";    // To continue working with older scripts, register as Simple.Target.

        protected override void SimpleInit()
        {
            foreach (Target t in ObjectPrivate.FindScripts <Target>("Simple.Target"))
            {
            }

            if (!StartEnabled)
            {
                Unregister();
            }

            SubscribeToAll(EnableEvent, (data) => { Register(); });
            SubscribeToAll(DisableEvent, (data) => { Unregister(); });
        }
Esempio n. 2
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.
        }
Esempio n. 3
0
        void OnSelect(CommandData command)
        {
            try
            {
                if (!FreeCamEnabled && command.CameraControlMode == CameraControlMode.FlyCam)
                {
                    AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                    user.SendChat("This device does not work in Free Cam mode, return to 1st or 3rd person views to use this device.");
                    return;
                }

                switch (command.ControlPoint)
                {
                case ControlPointType.DesktopGrab:
                    if (!MouseLookEnabled && command.MouseLookMode)
                    {
                        AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                        user.SendChat("This device does not work in desktop Mouse Look Mode: press Escape to enter or exit Mouse Look.");
                        return;
                    }
                    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;
                    }
                    break;

                case ControlPointType.LeftTool:
                case ControlPointType.RightTool:
                    if (!VREnabled)
                    {
                        AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                        user.SendChat("This device does not work in VR.");
                        return;
                    }

                    // Check hand after CheckReload which handles "shooting yourself to reload"
                    // If they grabbed it in desktop let them use it from whichever hand now? I guess?
                    if (heldHand != ControlPointType.DesktopGrab && command.ControlPoint != heldHand)
                    {
                        return;
                    }
                    break;

                default:
                    break;
                }

                SendToAll(EveryCommandEvent, simpleData);

                var targetAgent = ScenePrivate.FindAgent(command.TargetingComponent.ObjectId);
                if (targetAgent != null)
                {
                    SimpleData targetSimpleData = new SimpleData(this);
                    targetSimpleData.AgentInfo      = targetAgent.AgentInfo;
                    targetSimpleData.ObjectId       = targetSimpleData.AgentInfo.ObjectId;
                    targetSimpleData.SourceObjectId = simpleData.SourceObjectId;

                    SendToAll(PlayerSelectedEvent, targetSimpleData);
                }
                else
                {
                    ObjectPrivate targetObject = ScenePrivate.FindObject(command.TargetingComponent.ObjectId);
                    if (targetObject != null)
                    {
                        SimpleData targetSimpleData = new SimpleData(this);
                        targetSimpleData.AgentInfo      = null;
                        targetSimpleData.ObjectId       = targetObject.ObjectId;
                        targetSimpleData.SourceObjectId = simpleData.SourceObjectId;

                        ITarget target = targetObject.FindScripts <ITarget>("Simple.Target").FirstOrDefault();
                        if (target == null ||
                            (SameGroupRequired && target.GetGroupTag() != base.Group))
                        {
                            SendToAll(ObjectSelectedEvent, targetSimpleData);
                            return;
                        }
                        else
                        {
                            target.Hit(holdingAgent, command);
                            SendToAll(TargetSelectedEvent, targetSimpleData);
                            return;
                        }
                    }

                    SendToAll(NothingSelectedEvent, simpleData);
                }
            }
            catch (System.Exception) { } // ignore exceptions for not found agents.
        }
Esempio n. 4
0
        void OnTrigger(CommandData command)
        {
            try
            {
                if (!FreeCamEnabled && command.CameraControlMode == CameraControlMode.FlyCam)
                {
                    AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                    user.SendChat("This device does not work in Free Cam mode, return to 1st or 3rd person views to use this device.");
                    return;
                }

                switch (command.ControlPoint)
                {
                case ControlPointType.DesktopGrab:
                    if (!MouseLookEnabled && command.MouseLookMode)
                    {
                        AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                        user.SendChat("This device does not work in desktop Mouse Look Mode: press Escape to enter or exit Mouse Look.");
                        return;
                    }
                    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;
                    }
                    break;

                case ControlPointType.LeftTool:
                case ControlPointType.RightTool:
                    if (!VREnabled)
                    {
                        AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);
                        user.SendChat("This device does not work in VR.");
                        return;
                    }

                    // If they grabbed it in desktop let them use it from whichever hand now? I guess?
                    if (heldHand != ControlPointType.DesktopGrab && command.ControlPoint != heldHand)
                    {
                        return;
                    }
                    break;

                default:
                    break;
                }

                if (ClipSize > 0 && ammo <= 0)
                {
                    SendToAll(OutOfAmmoEvent, simpleData);
                    return;
                }

                SendToAll(ShotFiredEvent, simpleData);
                shotsFired++;
                ammo--;

                var targetAgent = ScenePrivate.FindAgent(command.TargetingComponent.ObjectId);
                if (targetAgent != null)
                {
                    shotsHit++;
                    score += PointsPerPlayer;
                    SendToAll(PlayerHitEvent, simpleData);

                    SimpleData targetSimpleData = new SimpleData(this);
                    targetSimpleData.AgentInfo      = targetAgent.AgentInfo;
                    targetSimpleData.ObjectId       = targetSimpleData.AgentInfo.ObjectId;
                    targetSimpleData.SourceObjectId = simpleData.SourceObjectId;

                    SendToAll(ShotHitEvent, targetSimpleData);
                }
                else
                {
                    ObjectPrivate targetObject = ScenePrivate.FindObject(command.TargetingComponent.ObjectId);
                    if (targetObject != null)
                    {
                        ITarget target = targetObject.FindScripts <ITarget>("Simple.Target").FirstOrDefault();
                        if (target != null &&
                            (!SameGroupRequired || target.GetGroupTag() == Group))
                        {
                            SimpleData targetSimpleData = new SimpleData(this);
                            targetSimpleData.AgentInfo      = null;
                            targetSimpleData.ObjectId       = targetObject.ObjectId;
                            targetSimpleData.SourceObjectId = simpleData.SourceObjectId;

                            SendToAll(ShotHitEvent, targetSimpleData);
                            score += target.Hit(holdingAgent, command);
                            shotsHit++;
                            return;
                        }
                    }

                    SendToAll(ShotMissEvent, simpleData);
                }
            }
            catch (System.Exception) { } // ignore exceptions for not found agents.
        }
Esempio n. 5
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.
        }