Ejemplo n.º 1
0
        private static bool OnAttach(MyMechanicalConnectionBlockBase __instance, MyAttachableTopBlockBase top)
        {
            if (!BlockLimiterConfig.Instance.MergerBlocking || !BlockLimiterConfig.Instance.EnableLimits || !MySession.Static.Ready)
            {
                return(true);
            }
            var topGrid  = top.CubeGrid;
            var baseGrid = __instance.CubeGrid;

            var      remoteUserId = MyEventContext.Current.Sender.Value;
            DateTime topDateTime  = default;

            if (_lastChecked.TryGetValue(__instance.EntityId, out var inDateTime) || _lastChecked.TryGetValue(top.EntityId, out topDateTime))
            {
                if (Math.Abs((DateTime.Now - inDateTime).Seconds) > 10)
                {
                    _lastChecked.Remove(__instance.EntityId);
                }
                if (Math.Abs((DateTime.Now - topDateTime).Seconds) > 10)
                {
                    _lastChecked.Remove(top.EntityId);
                }

                if (remoteUserId <= 0)
                {
                    return(false);
                }
                Utilities.SendFailSound(remoteUserId);
                Utilities.ValidationFailed(remoteUserId);
                return(false);
            }
            var result = Grid.CanMerge(topGrid, baseGrid, out var blocks, out var count, out var limitName);

            if (result)
            {
                return(true);
            }

            _lastChecked[__instance.EntityId] = DateTime.Now;
            _lastChecked[top.EntityId]        = DateTime.Now;

            BlockLimiter.Instance.Log.Info($"Blocked attachement between {baseGrid.DisplayName} and {topGrid.DisplayName}");

            if (remoteUserId <= 0)
            {
                return(false);
            }
            Utilities.SendFailSound(remoteUserId);
            Utilities.ValidationFailed(remoteUserId);
            var msg = Utilities.GetMessage(BlockLimiterConfig.Instance.DenyMessage, blocks, limitName, count);

            BlockLimiter.Instance.Torch.CurrentSession.Managers.GetManager <ChatManagerServer>()?
            .SendMessageAsOther(BlockLimiterConfig.Instance.ServerName, msg, Color.Red, remoteUserId);
            topGrid.RemoveBlock(top.SlimBlock);
            baseGrid.RemoveBlock(__instance.SlimBlock);
            return(false);
        }
        // ReSharper disable once InconsistentNaming
        private static void InitPatch(MyMechanicalConnectionBlockBase __instance)
        {
            var blockDefinition = (MyMechanicalConnectionBlockBaseDefinition)__instance.BlockDefinition;

            _safetyDetach.GetSync <float>(__instance).ValueChangedInRange(
                blockDefinition.SafetyDetachMin,
                blockDefinition.SafetyDetachMax
                );
        }
Ejemplo n.º 3
0
        public Vector3?GetPivot(MyCubeGrid grid, bool parent = false)
        {
            MyMechanicalConnectionBlockBase entityConnectingToParent = this.GetEntityConnectingToParent(grid) as MyMechanicalConnectionBlockBase;

            if (entityConnectingToParent != null)
            {
                return(entityConnectingToParent.GetConstraintPosition(grid, parent));
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static bool DetachDetection(MyMechanicalConnectionBlockBase __instance)
        {
            if (IsIrrelevantType(__instance))
            {
                return(true);
            }

            var motor = __instance as MyMotorBase;

            var session = RotorgunDetectorPlugin.Instance.Torch.CurrentSession;

            if (session == null || session.State != TorchSessionState.Loaded)
            {
                return(true);
            }

            RotorgunDetectorPlugin plugin = RotorgunDetectorPlugin.Instance;

            var grid = motor.CubeGrid;

            if (!IsPossibleRotorgun(grid, plugin.MinRotorGridCount))
            {
                return(true);
            }

            var cooldowns = plugin.DetachCooldowns;
            var key       = new EntityIdCooldownKey(grid.EntityId);

            if (!cooldowns.CheckCooldown(key, "detach", out long remainingSeconds))
            {
                long ownerId = motor.OwnerId;

                if (ownerId != 0)
                {
                    MyVisualScriptLogicProvider.SendChatMessage("Rotor Head cannot be placed for an other " + remainingSeconds + " seconds.", "Server", ownerId, "Red");
                }

                DoLogging(key, grid);

                return(false);
            }

            cooldowns.StartCooldown(key, "detach", plugin.DetachCooldown);

            return(true);
        }
Ejemplo n.º 5
0
        public static bool IsIrrelevantType(MyMechanicalConnectionBlockBase block)
        {
            if (!(block is MyMotorStator stator))
            {
                return(true);
            }

            if (stator.BlockDefinition is MyMotorStatorDefinition definition)
            {
                if (definition.RotorType != MyRotorType.Rotor)
                {
                    return(true);
                }
            }

            return(false);
        }