Exemplo n.º 1
0
        public void EnableProtection(IMySlimBlock slimBlock)
        {
            using (Log.BeginMethod(nameof(EnableProtection))) {
                if (slimBlock == null)
                {
                    return;
                }

                Log.Debug($"Enable protection for: {slimBlock}");
                var cubeGrid = slimBlock.CubeGrid;
                if (_protectedInfos.ContainsKey(cubeGrid.EntityId))
                {
                    _protectedInfos[cubeGrid.EntityId].EnableProtection(slimBlock);
                }
                else
                {
                    var protectInfo = new ProtectInfo(cubeGrid);
                    protectInfo.EnableProtection(slimBlock);
                    _protectedInfos.Add(cubeGrid.EntityId, protectInfo);
                    cubeGrid.OnClose += OnClose;
                }
            }
        }
Exemplo n.º 2
0
        private void HandleProtectedBlockDamage(ProtectInfo protectInfo, AttackerInfo attacker, ref MyDamageInformation damage)
        {
            var toleranceMultiplier = Mod.Static.Settings.ImpactToleranceMultiplier;

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (toleranceMultiplier == 0)
            {
                damage.Amount        = 0;
                damage.IsDeformation = false;
                return;
            }

            var linearVelocity  = protectInfo.LinearVelocity;
            var mass            = protectInfo.Mass;
            var impactTolerance = Math.Pow(mass / 1000, -0.1) * MAX_IMPACT_TOLERANCE;

            var attackerLinearVelocity = attacker.LinearVelocity;

            var impactVelocity = (attackerLinearVelocity - linearVelocity).Length();
            var tolerance      = Math.Min(Math.Max(impactTolerance, MIN_IMPACT_TOLERANCE), MAX_IMPACT_TOLERANCE) * toleranceMultiplier;

            if (impactVelocity <= tolerance * 2.5)
            {
                if (impactVelocity <= tolerance)
                {
                    damage.Amount        = 0;
                    damage.IsDeformation = false;
                }
                else
                {
                    var multiplier = Math.Pow(impactVelocity / tolerance, .75) - 1;
                    damage.Amount       *= (float)multiplier;
                    damage.IsDeformation = false;
                }
            }
        }