Ejemplo n.º 1
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                _tick   = Session.Instance.Tick;
                _tick60 = _tick % 60 == 0;
                var wait = _isServer && !_tick60 && EmiState.State.Backup;

                MyGrid = MyCube.CubeGrid;
                if (wait || MyGrid?.Physics == null)
                {
                    return;
                }

                IsStatic = MyGrid.IsStatic;
                Timing();
                if (!ControllerLink())
                {
                    return;
                }

                if (!_isDedicated && UtilsStatic.DistanceCheck(Emitter, 1000, EmiState.State.BoundingRange))
                {
                    var blockCam = MyCube.PositionComp.WorldVolume;
                    if (MyAPIGateway.Session.Camera.IsInFrustum(ref blockCam))
                    {
                        BlockMoveAnimation();
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in UpdateBeforeSimulation: {ex}"); }
        }
Ejemplo n.º 2
0
        private void UpdateUnitSphere()
        {
            var losPointSphere = Session.Instance.LosPointSphere;

            LosScaledCloud.Clear();
            UtilsStatic.UnitSphereTranslateScaleList(_unitSpherePoints, ref losPointSphere, ref LosScaledCloud, ShieldComp.DefenseShields.ShieldEnt, false, MyGrid);
        }
Ejemplo n.º 3
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                if (!EntityAlive())
                {
                    return;
                }
                var shield = ShieldOn();
                if (shield != State.Active)
                {
                    if (NotFailed)
                    {
                        if (Session.Enforced.Debug >= 2)
                        {
                            Log.Line($"FailState: {shield} - ShieldId [{Shield.EntityId}]");
                        }
                        var up    = shield != State.Lowered;
                        var awake = shield != State.Sleep;
                        var clear = up && awake;
                        OfflineShield(clear, up);
                    }
                    else if (DsState.State.Message)
                    {
                        ShieldChangeState();
                    }
                    return;
                }

                if (!_isServer || !DsState.State.Online)
                {
                    return;
                }
                if (_comingOnline)
                {
                    ComingOnlineSetup();
                }
                if (_mpActive && (_forceBufferSync || _count == 29))
                {
                    var newPercentColor = UtilsStatic.GetShieldColorFromFloat(DsState.State.ShieldPercent);
                    if (_forceBufferSync || newPercentColor != _oldPercentColor)
                    {
                        ShieldChangeState();
                        _oldPercentColor = newPercentColor;
                        _forceBufferSync = false;
                    }
                    else if (_tick180)
                    {
                        ShieldChangeState();
                    }
                }
                if (Session.Instance.EmpWork.EventRunning)
                {
                    AbsorbEmp();
                }
            }
            catch (Exception ex) { Log.Line($"Exception in UpdateBeforeSimulation: {ex}"); }
        }
Ejemplo n.º 4
0
        private void UpdateUnitSphere()
        {
            var losPointSphere = Session.Instance.LosPointSphere;

            LosScaledCloud.Clear();
            var checkSphere = new BoundingSphereD(ShieldComp.DefenseShields.MyGridCenter, ShieldComp.DefenseShields.DsState.State.GridHalfExtents.Length() + 20);

            UtilsStatic.UnitSphereTranslateScaleList(_unitSpherePoints, ref losPointSphere, ref LosScaledCloud, ref checkSphere, ShieldComp.DefenseShields.ShieldEnt, false, MyGrid);
        }
Ejemplo n.º 5
0
 private void GetShapeAdjust()
 {
     if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield)
     {
         DsState.State.EllipsoidAdjust = 1f;
     }
     else
     {
         DsState.State.EllipsoidAdjust = UtilsStatic.GetFit(DsSet.Settings.Fit);
     }
 }
Ejemplo n.º 6
0
        private void AbsorbClientShieldHits()
        {
            for (int i = 0; i < ShieldHits.Count; i++)
            {
                var hit        = ShieldHits[i];
                var damageType = hit.DamageType;

                if (!WasOnline)
                {
                    continue;
                }

                if (damageType == Session.Instance.MPExplosion)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = true;
                    Absorb += hit.Amount * ConvToWatts;
                    UtilsStatic.CreateFakeSmallExplosion(WorldImpactPosition);
                    if (hit.Attacker != null)
                    {
                        hit.Attacker.Close();
                        hit.Attacker.InScene = false;
                    }
                    continue;
                }
                if (damageType == Session.Instance.MPKinetic)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = false;
                    Absorb += hit.Amount * ConvToWatts;
                    continue;
                }
                if (damageType == Session.Instance.MPEnergy)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = true;
                    Absorb += hit.Amount * ConvToWatts;
                    continue;
                }
                if (damageType == Session.Instance.MPEMP)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = true;
                    Absorb += hit.Amount * ConvToWatts;
                    continue;
                }
            }
            ShieldHits.Clear();
        }
Ejemplo n.º 7
0
        private float ComputeAmmoDamage(IMyEntity ammoEnt)
        {
            AmmoInfo ammoInfo;

            Session.Instance.AmmoCollection.TryGetValue(ammoEnt.Model.AssetName, out ammoInfo);
            var damage = 10f;

            if (ammoInfo == null)
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"ShieldId:{Shield.EntityId.ToString()} - No Missile Ammo Match Found for {((MyEntity)ammoEnt).DebugName}! Let wepaon mod author know their ammo definition has improper model path");
                }
                return(damage);
            }
            var dmgMulti = UtilsStatic.GetDmgMulti(ammoInfo.BackKickForce);

            if (dmgMulti > 0)
            {
                if (ammoInfo.Explosive)
                {
                    damage = (ammoInfo.Damage * (ammoInfo.Radius * 0.5f)) * 7.5f * dmgMulti;
                }
                else
                {
                    damage = ammoInfo.Mass * ammoInfo.Speed * dmgMulti;
                }
                return(damage);
            }
            if (dmgMulti.Equals(-1f))
            {
                damage = -damage;
                return(damage);
            }
            if (ammoInfo.BackKickForce < 0 && dmgMulti.Equals(0))
            {
                damage = float.NegativeInfinity;
            }
            else if (ammoInfo.Explosive)
            {
                damage = ammoInfo.Damage * (ammoInfo.Radius * 0.5f) * 7.5f;
            }
            else
            {
                damage = ammoInfo.Mass * ammoInfo.Speed;
            }

            if (ammoInfo.Mass < 0 && ammoInfo.Radius <= 0)
            {
                damage = -damage;
            }
            return(damage);
        }
Ejemplo n.º 8
0
        private void AbsorbClientShieldHits()
        {
            for (int i = 0; i < ShieldHits.Count; i++)
            {
                var hit        = ShieldHits[i];
                var damageType = hit.DamageType;

                if (!NotFailed)
                {
                    continue;
                }

                if (damageType == Session.Instance.MPExplosion)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = HitType.Energy;
                    Absorb += hit.Amount * ConvToWatts;
                    UtilsStatic.CreateFakeSmallExplosion(WorldImpactPosition);
                    if (hit.Attacker != null)
                    {
                        ((IMyDestroyableObject)hit.Attacker).DoDamage(1, Session.Instance.MPKinetic, false, null, ShieldEnt.EntityId);
                    }
                    continue;
                }
                if (damageType == Session.Instance.MPKinetic)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = HitType.Kinetic;
                    Absorb += hit.Amount * ConvToWatts;
                    continue;
                }
                if (damageType == Session.Instance.MPEnergy)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = HitType.Energy;
                    Absorb += hit.Amount * ConvToWatts;
                    continue;
                }
                if (damageType == Session.Instance.MPEMP)
                {
                    ImpactSize          = hit.Amount;
                    WorldImpactPosition = hit.HitPos;
                    EnergyHit           = HitType.Energy;
                    Absorb += hit.Amount * ConvToWatts;
                    continue;
                }
            }
            ShieldHits.Clear();
        }
Ejemplo n.º 9
0
 private void ResetAirEmissives(double tenPercent)
 {
     for (int i = 0; i < 10; i++)
     {
         if (tenPercent < 0 || i > tenPercent)
         {
             O2Generator.SetEmissiveParts("Emissive" + i, Color.Transparent, 0f);
         }
         else
         {
             O2Generator.SetEmissiveParts("Emissive" + i, UtilsStatic.GetAirEmissiveColorFromDouble(i * 10), 1f);
         }
     }
 }
Ejemplo n.º 10
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                _tick   = Session.Instance.Tick;
                _tock33 = _tick % 33 == 0;
                _tock34 = _tick % 34 == 0;
                if (_count++ == 59)
                {
                    _count  = 0;
                    _tock60 = true;
                }
                else
                {
                    _tock60 = false;
                }

                var wait = _isServer && _count != 0 && ModState.State.Backup;

                MyGrid = MyCube.CubeGrid;
                if (wait || MyGrid?.Physics == null)
                {
                    return;
                }

                Timing();

                if (!ModulatorReady())
                {
                    ModulatorOff();
                    return;
                }
                ModulatorOn();
                if (!_isDedicated && UtilsStatic.DistanceCheck(Modulator, 1000, 1))
                {
                    var blockCam = MyCube.PositionComp.WorldVolume;
                    if (MyAPIGateway.Session.Camera.IsInFrustum(ref blockCam) && ModState.State.Online)
                    {
                        BlockMoveAnimation();
                    }
                }

                if (_isServer)
                {
                    UpdateStates();
                }
                _firstRun = false;
            }
            catch (Exception ex) { Log.Line($"Exception in UpdateBeforeSimulation: {ex}"); }
        }
Ejemplo n.º 11
0
        private void UpdateUnitSphere(bool updateShape = false)
        {
            if (updateShape)
            {
                if (ShieldComp.DefenseShields.GridIsMobile)
                {
                    ShieldComp.DefenseShields.MobileUpdate();
                }
            }
            var losPointSphere = Session.Instance.LosPointSphere;

            LosScaledCloud.Clear();
            UtilsStatic.UnitSphereTranslateScaleList(_unitSpherePoints, ref losPointSphere, ref LosScaledCloud, ShieldComp.DefenseShields.ShieldEnt, false, MyGrid);
        }
Ejemplo n.º 12
0
 private void GetShapeAdjust()
 {
     if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield)
     {
         DsState.State.EllipsoidAdjust = 1f;
     }
     //else if (!DsSet.Settings.ExtendFit) DsState.State.EllipsoidAdjust = UtilsStatic.CreateNormalFit((MyCubeBlock)Shield, DsState.State.GridHalfExtents, FitBlocks, FitBlockPoints);
     //else DsState.State.EllipsoidAdjust = UtilsStatic.CreateExtendedFit((MyCubeBlock)Shield, DsState.State.GridHalfExtents, FitBlocks, FitBlockPoints);
     else
     {
         DsState.State.EllipsoidAdjust = UtilsStatic.GetFit(DsSet.Settings.Fit);
     }
     FitBlocks.Clear();
 }
Ejemplo n.º 13
0
 private void GetShapeAdjust()
 {
     if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield)
     {
         DsState.State.EllipsoidAdjust = 1f;
     }
     else if (!DsSet.Settings.ExtendFit)
     {
         DsState.State.EllipsoidAdjust = UtilsStatic.CreateNormalFit(Shield, DsState.State.GridHalfExtents);
     }
     else
     {
         DsState.State.EllipsoidAdjust = UtilsStatic.CreateExtendedFit(Shield, DsState.State.GridHalfExtents);
     }
 }
Ejemplo n.º 14
0
        private void UpdateDisplay()
        {
            var ds = ShieldComp.DefenseShields;

            if (_imagesDetected && Set.Settings.Report == 2)
            {
                if (Display.ShowText)
                {
                    Display.ShowTextureOnScreen();
                }
                var image    = UtilsStatic.GetShieldThyaFromFloat(ds.DsState.State.ShieldPercent, 0);
                var oldImage = Display.CurrentlyShownImage;

                if (oldImage != image)
                {
                    Display.RemoveImageFromSelection(oldImage, true);
                    Display.AddImageToSelection(image);
                    Display.NeedsUpdate &= ~MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                }
            }
            else
            {
                if (!Display.ShowText)
                {
                    Display.ShowPublicTextOnScreen();
                    if (Display.FontSize <= 1)
                    {
                        Display.FontSize = 1.30f;
                    }
                }
                if (Tick - ds.LastCustomInfoUpdate >= 99)
                {
                    ds.Shield.RefreshCustomInfo();
                }
                Display.WritePublicText(ds.Shield.CustomInfo);
            }
        }
Ejemplo n.º 15
0
        private void GetFilteredItems(Vector3D epiCenter, double rangeCap, double dirYield)
        {
            _warHeadCubeHits.Clear();
            _warHeadGridShapes.Clear();
            var myCubeList = new List <MyEntity>();

            foreach (var grid in _warHeadGridHits)
            {
                var invSqrDist = UtilsStatic.InverseSqrDist(epiCenter, grid.PositionComp.WorldAABB.Center, rangeCap);
                var damage     = (uint)(dirYield * invSqrDist) * 5;
                var gridAabb   = grid.PositionComp.WorldAABB;
                var sphere     = CustomCollision.NewObbClosestTriCorners(grid, epiCenter);

                grid.Hierarchy.QueryAABB(ref gridAabb, myCubeList);
                _warHeadGridShapes.Add(grid, new WarHeadHit(sphere, damage));
            }

            for (int i = 0; i < myCubeList.Count; i++)
            {
                var myEntity = myCubeList[i];
                var myCube   = myEntity as MyCubeBlock;

                if (myCube == null || myCube.MarkedForClose)
                {
                    continue;
                }
                if ((myCube is IMyThrust || myCube is IMyUserControllableGun || myCube is IMyUpgradeModule) && myCube.IsFunctional && myCube.IsWorking)
                {
                    _warHeadCubeHits.Add(myCube);
                }
            }
            if (Enforced.Debug >= 2)
            {
                Log.Line($"[ComputeEmpBlast] AllFat:{myCubeList.Count} - TrimmedFat:{_warHeadCubeHits.Count}");
            }
        }
Ejemplo n.º 16
0
        private void Timings()
        {
            _newFrame = true;
            Tick      = (uint)(Session.ElapsedPlayTime.TotalMilliseconds * TickTimeDiv);
            Tick20    = Tick % 20 == 0;
            Tick60    = Tick % 60 == 0;
            Tick60    = Tick % 60 == 0;
            Tick180   = Tick % 180 == 0;
            Tick600   = Tick % 600 == 0;
            Tick1800  = Tick % 1800 == 0;

            if (_count++ == 59)
            {
                _count = 0;
                _lCount++;
                if (_lCount == 10)
                {
                    _lCount = 0;
                    _eCount++;
                    if (_eCount == 10)
                    {
                        _eCount = 0;
                    }
                }
            }
            if (!GameLoaded && Tick > 100)
            {
                if (!WarHeadLoaded && WarTerminalReset != null)
                {
                    WarTerminalReset.ShowInTerminal = true;
                    WarTerminalReset = null;
                    WarHeadLoaded    = true;
                }

                if (!MiscLoaded)
                {
                    MiscLoaded = true;
                    UtilsStatic.GetDefinitons();
                    if (!IsServer)
                    {
                        Players.TryAdd(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.Player);
                    }
                }
                GameLoaded = true;
            }

            if (EmpWork.EventRunning && EmpWork.Computed)
            {
                EmpWork.EventComplete();
            }

            if (Tick20)
            {
                Scale();
                EntSlotTick = Tick % (180 / EntSlotScaler) == 0;
                if (EntSlotTick)
                {
                    LoadBalancer();
                }
            }
            else
            {
                EntSlotTick = false;
            }
        }
Ejemplo n.º 17
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                if (!EntityAlive() || !_isServer && !ClientInitPacket)
                {
                    return;
                }

                if (!_isDedicated && _clientMessageCount < DsState.State.MessageCount)
                {
                    BroadcastMessage();
                }

                var shield = ShieldOn();
                if (shield != State.Active)
                {
                    if (NotFailed)
                    {
                        if (Session.Enforced.Debug >= 2)
                        {
                            Log.Line($"FailState: {shield} - ShieldId [{Shield.EntityId}]");
                        }
                        var up    = shield != State.Lowered;
                        var awake = shield != State.Sleep;
                        var clear = up && awake;
                        OfflineShield(clear, up);
                    }
                    else if (_isServer && _sendMessage)
                    {
                        ShieldChangeState();
                    }
                    return;
                }

                if (!_isServer)
                {
                    return;
                }

                if (!DsState.State.Online && DsState.State.ActiveEmitterId != 0 && _tick600)
                {
                    ShieldChangeState();
                    return;
                }

                if (_comingOnline)
                {
                    ComingOnlineSetup();
                }
                if (_mpActive && (_forceBufferSync || _count == 29 || _tick180))
                {
                    var newPercentColor = UtilsStatic.GetShieldColorFromFloat(DsState.State.ShieldPercent);
                    if (_forceBufferSync || newPercentColor != _oldPercentColor)
                    {
                        ShieldChangeState();
                        _oldPercentColor = newPercentColor;
                        _forceBufferSync = false;
                    }
                    else if (_tick180)
                    {
                        ShieldChangeState();
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in UpdateBeforeSimulation: {ex}"); }
        }
Ejemplo n.º 18
0
        private void Timings()
        {
            Tick     = (uint)(Session.ElapsedPlayTime.TotalMilliseconds * TickTimeDiv);
            Tick20   = Tick % 20 == 0;
            Tick30   = Tick % 30 == 0;
            Tick60   = Tick % 60 == 0;
            Tick60   = Tick % 60 == 0;
            Tick180  = Tick % 180 == 0;
            Tick300  = Tick % 300 == 0;
            Tick600  = Tick % 600 == 0;
            Tick1800 = Tick % 1800 == 0;

            if (_count++ == 59)
            {
                _count = 0;
                _lCount++;
                if (_lCount == 10)
                {
                    _lCount = 0;
                    _eCount++;
                    if (_eCount == 10)
                    {
                        _eCount        = 0;
                        _previousEntId = -1;
                    }
                }
            }
            if (!GameLoaded)
            {
                if (!MiscLoaded)
                {
                    if (SessionReady && GlobalProtect.Count > 0 && (IsServer || !IsServer && ClientLoadCount++ > 60))
                    {
                        UtilsStatic.GetDefinitons();
                        if (!IsServer)
                        {
                            Players.TryAdd(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.Player);
                        }
                        Api.Init();
                        MiscLoaded = true;
                        GameLoaded = true;
                    }
                }

                if (MiscLoaded && !WarHeadLoaded && WarTerminalReset != null)
                {
                    WarTerminalReset.ShowInTerminal = true;
                    WarTerminalReset = null;
                    WarHeadLoaded    = true;
                    GameLoaded       = true;
                }
            }

            if (EmpWork.EventRunning && EmpWork.Computed)
            {
                EmpWork.EventComplete();
            }

            if (Tick20)
            {
                Scale();
                EntSlotTick = Tick % (180 / EntSlotScaler) == 0;
                if (EntSlotTick)
                {
                    LoadBalancer();
                }
            }
            else
            {
                EntSlotTick = false;
            }
        }
Ejemplo n.º 19
0
        private void SyncThreadedEnts(bool clear = false, bool client = false)
        {
            try
            {
                if (clear)
                {
                    Eject.Clear();
                    DestroyedBlocks.Clear();
                    MissileDmg.Clear();
                    MeteorDmg.Clear();
                    VoxelDmg.Clear();
                    CharacterDmg.Clear();
                    FewDmgBlocks.Clear();
                    CollidingBlocks.Clear();
                    ForceData.Clear();
                    ImpulseData.Clear();
                    return;
                }

                try
                {
                    if (!Eject.IsEmpty)
                    {
                        MyCubeGrid myGrid;
                        while (Eject.TryDequeue(out myGrid))
                        {
                            if (myGrid == null || myGrid.MarkedForClose)
                            {
                                continue;
                            }
                            myGrid.Physics.LinearVelocity *= -0.25f;
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in Eject: {ex}"); }

                try
                {
                    if (!ForceData.IsEmpty)
                    {
                        MyAddForceData data;
                        while (ForceData.TryDequeue(out data))
                        {
                            var myGrid = data.MyGrid;
                            if (myGrid == null || myGrid.MarkedForClose)
                            {
                                continue;
                            }
                            myGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, data.Force, null, Vector3D.Zero, data.MaxSpeed, data.Immediate);
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in forceData: {ex}"); }

                try
                {
                    if (!ImpulseData.IsEmpty)
                    {
                        MyImpulseData data;
                        while (ImpulseData.TryDequeue(out data))
                        {
                            var myGrid = data.MyGrid;
                            if (myGrid == null || myGrid.MarkedForClose)
                            {
                                continue;
                            }
                            myGrid.Physics.ApplyImpulse(data.Direction, data.Position);
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in impulseData: {ex}"); }

                if (client)
                {
                    return;
                }

                try
                {
                    if (!DestroyedBlocks.IsEmpty)
                    {
                        IMySlimBlock block;
                        var          nullCount = 0;
                        while (DestroyedBlocks.TryDequeue(out block))
                        {
                            var myGrid = block.CubeGrid as MyCubeGrid;
                            if (myGrid == null)
                            {
                                continue;
                            }
                            EntIntersectInfo entInfo;
                            WebEnts.TryGetValue(myGrid, out entInfo);
                            if (entInfo == null)
                            {
                                nullCount++;
                                myGrid.EnqueueDestroyedBlock(block.Position);
                                continue;
                            }

                            EntIntersectInfo entRemoved;
                            if (nullCount > 0)
                            {
                                WebEnts.TryRemove(myGrid, out entRemoved);
                            }
                            entInfo.CacheBlockList.Remove(block);
                            myGrid.EnqueueDestroyedBlock(block.Position);
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in destroyedBlocks: {ex}"); }

                try
                {
                    if (!MissileDmg.IsEmpty)
                    {
                        MyEntity ent;
                        while (MissileDmg.TryDequeue(out ent))
                        {
                            if (ent == null || !ent.InScene || ent.MarkedForClose)
                            {
                                continue;
                            }
                            var computedDamage = ComputeAmmoDamage(ent);

                            var damage = computedDamage * DsState.State.ModulateKinetic;
                            if (computedDamage < 0)
                            {
                                damage = computedDamage;
                            }

                            var rayDir    = Vector3D.Normalize(ent.Physics.LinearVelocity);
                            var ray       = new RayD(ent.PositionComp.WorldVolume.Center, rayDir);
                            var intersect = CustomCollision.IntersectEllipsoid(DetectMatrixOutsideInv, DetectionMatrix, ray);
                            var hitDist   = intersect ?? 0;
                            var hitPos    = ray.Position + (ray.Direction * -hitDist);

                            if (_mpActive)
                            {
                                AddShieldHit(ent.EntityId, damage, Session.Instance.MPExplosion, null, false, hitPos);
                                ent.Close();
                                ent.InScene = false;
                            }
                            else
                            {
                                EnergyHit           = true;
                                WorldImpactPosition = hitPos;
                                Absorb    += damage;
                                ImpactSize = damage;
                                UtilsStatic.CreateFakeSmallExplosion(hitPos);
                                ent.Close();
                                ent.InScene = false;
                            }
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in missileDmg: {ex}"); }

                try
                {
                    if (!MeteorDmg.IsEmpty)
                    {
                        IMyMeteor meteor;
                        while (MeteorDmg.TryDequeue(out meteor))
                        {
                            if (meteor == null || meteor.MarkedForClose || meteor.Closed)
                            {
                                continue;
                            }
                            var damage = 5000 * DsState.State.ModulateEnergy;
                            if (_mpActive)
                            {
                                AddShieldHit(meteor.EntityId, damage, Session.Instance.MPKinetic, null, false, meteor.PositionComp.WorldVolume.Center);
                                meteor.DoDamage(10000f, Session.Instance.MpIgnoreDamage, true, null, MyCube.EntityId);
                            }
                            else
                            {
                                WorldImpactPosition = meteor.PositionComp.WorldVolume.Center;
                                Absorb    += damage;
                                ImpactSize = damage;
                                meteor.DoDamage(10000f, Session.Instance.MpIgnoreDamage, true, null, MyCube.EntityId);
                            }
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in missileDmg: {ex}"); }

                try
                {
                    if (!VoxelDmg.IsEmpty)
                    {
                        MyVoxelBase voxel;
                        while (VoxelDmg.TryDequeue(out voxel))
                        {
                            if (voxel == null || voxel.RootVoxel.MarkedForClose || voxel.RootVoxel.Closed)
                            {
                                continue;
                            }
                            voxel.RootVoxel.RequestVoxelOperationElipsoid(Vector3.One * 1.0f, DetectMatrixOutside, 0, MyVoxelBase.OperationType.Cut);
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in missileDmg: {ex}"); }

                try
                {
                    if (!CharacterDmg.IsEmpty)
                    {
                        IMyCharacter character;
                        while (CharacterDmg.TryDequeue(out character))
                        {
                            var npcname = character.ToString();
                            if (npcname.Equals("Space_Wolf"))
                            {
                                character.Delete();
                                continue;
                            }
                            var hId            = MyCharacterOxygenComponent.HydrogenId;
                            var playerGasLevel = character.GetSuitGasFillLevel(hId);
                            character.Components.Get <MyCharacterOxygenComponent>().UpdateStoredGasLevel(ref hId, (playerGasLevel * -0.0001f) + .002f);
                            MyVisualScriptLogicProvider.CreateExplosion(character.GetPosition(), 0, 0);
                            character.DoDamage(50f, Session.Instance.MpIgnoreDamage, true, null, MyCube.EntityId);
                            var vel = character.Physics.LinearVelocity;
                            if (vel == new Vector3D(0, 0, 0))
                            {
                                vel = MyUtils.GetRandomVector3Normalized();
                            }
                            var speedDir        = Vector3D.Normalize(vel);
                            var rnd             = new Random();
                            var randomSpeed     = rnd.Next(10, 20);
                            var additionalSpeed = vel + (speedDir * randomSpeed);
                            character.Physics.LinearVelocity = additionalSpeed;
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in missileDmg: {ex}"); }

                try
                {
                    if (!CollidingBlocks.IsEmpty)
                    {
                        IMySlimBlock block;
                        var          damageMulti = 350;
                        if (ShieldMode == ShieldType.Station && DsState.State.Enhancer)
                        {
                            damageMulti = 10000;
                        }
                        while (CollidingBlocks.TryDequeue(out block))
                        {
                            if (block == null)
                            {
                                continue;
                            }
                            var myGrid = block.CubeGrid as MyCubeGrid;
                            if (block.IsDestroyed)
                            {
                                myGrid.EnqueueDestroyedBlock(block.Position);
                                continue;
                            }
                            block.DoDamage(damageMulti, Session.Instance.MpIgnoreDamage, true, null, MyCube.EntityId);
                            if (myGrid.BlocksCount == 0)
                            {
                                myGrid.SendGridCloseRequest();
                            }
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in dmgBlocks: {ex}"); }

                try
                {
                    if (!FewDmgBlocks.IsEmpty)
                    {
                        IMySlimBlock block;
                        while (FewDmgBlocks.TryDequeue(out block))
                        {
                            if (block == null)
                            {
                                continue;
                            }
                            var myGrid = block.CubeGrid as MyCubeGrid;

                            if (block.IsDestroyed)
                            {
                                myGrid.EnqueueDestroyedBlock(block.Position);
                                myGrid.Close();
                                continue;
                            }
                            block.DoDamage(block.MaxIntegrity * 0.9f, Session.Instance.MpIgnoreDamage, true, null, MyCube.EntityId);
                            if (myGrid.BlocksCount == 0)
                            {
                                myGrid.SendGridCloseRequest();
                            }
                        }
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in fewBlocks: {ex}"); }

                try
                {
                    if (Session.Instance.EmpWork.EventRunning && Vector3D.DistanceSquared(DetectionCenter, Session.Instance.EmpWork.EpiCenter) <= Session.Instance.EmpWork.RangeCapSqr)
                    {
                        var        empResistenceRatio    = 1f;
                        const long AttackerId            = 0L;
                        var        energyResistenceRatio = DsState.State.ModulateKinetic;
                        var        epiCenter             = Session.Instance.EmpWork.EpiCenter;
                        var        rangeCap    = Session.Instance.EmpWork.RangeCap;
                        var        empDirYield = Session.Instance.EmpWork.DirYield;

                        if (DsState.State.EmpProtection)
                        {
                            if (energyResistenceRatio < 0.4)
                            {
                                energyResistenceRatio = 0.4f;
                            }
                            empResistenceRatio = 0.1f;
                        }
                        //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - Start] ShieldOwner:{MyGrid.DebugName} - Yield:{warHeadYield} - StackCount:{stackCount} - ProtectionRatio:{energyResistenceRatio * empResistenceRatio} - epiCenter:{epiCenter}");
                        var line      = new LineD(epiCenter, SOriBBoxD.Center);
                        var testDir   = Vector3D.Normalize(line.From - line.To);
                        var ray       = new RayD(line.From, -testDir);
                        var ellipsoid = CustomCollision.IntersectEllipsoid(DetectMatrixOutsideInv, DetectionMatrix, ray);
                        if (!ellipsoid.HasValue)
                        {
                            //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - Ellipsoid null hit] ShieldOwner:{MyGrid.DebugName} - Yield:{warHeadYield} - StackCount:{stackCount} - ProtectionRatio:{energyResistenceRatio * empResistenceRatio} - epiCenter:{epiCenter}");
                            return;
                        }
                        var      impactPos = line.From + (testDir * -ellipsoid.Value);
                        IHitInfo hitInfo;
                        MyAPIGateway.Physics.CastRay(epiCenter, impactPos, out hitInfo, CollisionLayers.DefaultCollisionLayer);
                        if (hitInfo != null)
                        {
                            //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - occluded] ShieldOwner:{MyGrid.DebugName} - by {((MyEntity)hitInfo.HitEntity).DebugName}");
                            return;
                        }
                        var gridLocalMatrix    = MyGrid.PositionComp.LocalMatrix;
                        var worldDirection     = impactPos - gridLocalMatrix.Translation;
                        var localPosition      = Vector3D.TransformNormal(worldDirection, MatrixD.Transpose(gridLocalMatrix));
                        var hitFaceSurfaceArea = UtilsStatic.GetIntersectingSurfaceArea(ShieldShapeMatrix, localPosition);

                        var invSqrDist   = UtilsStatic.InverseSqrDist(epiCenter, impactPos, rangeCap);
                        var damageScaler = invSqrDist * hitFaceSurfaceArea;
                        if (invSqrDist <= 0)
                        {
                            //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - Range] ShieldOwner:{MyGrid.DebugName} - insqrDist was 0");
                            return;
                        }

                        var targetDamage = (float)(((empDirYield * damageScaler) * energyResistenceRatio) * empResistenceRatio);

                        if (targetDamage >= DsState.State.Charge * ConvToHp)
                        {
                            _empOverLoad = true;
                        }
                        //if (Session.Enforced.Debug >= 2) Log.Line($"-----------------------] epiDist:{Vector3D.Distance(epiCenter, impactPos)} - iSqrDist:{invSqrDist} - RangeCap:{rangeCap} - SurfaceA:{hitFaceSurfaceArea}({_ellipsoidSurfaceArea * 0.5}) - dirYield:{empDirYield} - damageScaler:{damageScaler} - Damage:{targetDamage}(toOver:{(targetDamage / (DsState.State.Charge * ConvToHp))})");

                        if (_isServer && _mpActive)
                        {
                            AddEmpBlastHit(AttackerId, targetDamage, Session.Instance.MPEMP, impactPos);
                        }

                        EnergyHit           = true;
                        WorldImpactPosition = epiCenter;
                        Absorb += targetDamage;
                    }
                }
                catch (Exception ex) { Log.Line($"Exception in EmpBlast: {ex}"); }
            }
            catch (Exception ex) { Log.Line($"Exception in DamageGrids: {ex}"); }
        }
Ejemplo n.º 20
0
 public Session()
 {
     UtilsStatic.UnitSphereRandomOnly(ref LosPointSphere);
 }
Ejemplo n.º 21
0
        public override void BeforeStart()
        {
            try
            {
                MpActive        = MyAPIGateway.Multiplayer.MultiplayerActive;
                IsServer        = MyAPIGateway.Multiplayer.IsServer;
                DedicatedServer = MyAPIGateway.Utilities.IsDedicated;
                HandlesInput    = !IsServer || IsServer && !DedicatedServer;

                var env = MyDefinitionManager.Static.EnvironmentDefinition;
                if (env.LargeShipMaxSpeed > MaxEntitySpeed)
                {
                    MaxEntitySpeed = env.LargeShipMaxSpeed;
                }
                else if (env.SmallShipMaxSpeed > MaxEntitySpeed)
                {
                    MaxEntitySpeed = env.SmallShipMaxSpeed;
                }

                Log.Init("debugdevelop.log");
                Log.Line($"Logging Started: Server:{IsServer} - Dedicated:{DedicatedServer} - MpActive:{MpActive}");

                MyAPIGateway.Session.DamageSystem.RegisterBeforeDamageHandler(0, CheckDamage);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PACKET_ID, ReceivedPacket);

                if (!DedicatedServer && IsServer)
                {
                    Players.TryAdd(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.Player);
                }
                MyEntities.OnEntityRemove                        += OnEntityRemove;
                MyAPIGateway.Session.OnSessionReady              += OnSessionReady;
                MyVisualScriptLogicProvider.PlayerDisconnected   += PlayerDisconnected;
                MyVisualScriptLogicProvider.PlayerRespawnRequest += PlayerConnected;
                if (!DedicatedServer)
                {
                    Password          = MyStringId.GetOrCompute(Localization.GetText("TerminalPasswordTitle"));
                    PasswordTooltip   = MyStringId.GetOrCompute(Localization.GetText("TerminalPasswordTooltip"));
                    ShieldFreq        = MyStringId.GetOrCompute(Localization.GetText("TerminalShieldFreqTitle"));
                    ShieldFreqTooltip = MyStringId.GetOrCompute(Localization.GetText("TerminalShieldFreqTooltip"));
                    MyAPIGateway.TerminalControls.CustomControlGetter += CustomControls;
                }

                if (IsServer)
                {
                    Log.Line("LoadConf - Session: This is a server");
                    UtilsStatic.PrepConfigFile();
                    UtilsStatic.ReadConfigFile();
                }

                if (MpActive)
                {
                    SyncDist            = MyAPIGateway.Session.SessionSettings.SyncDistance;
                    SyncDistSqr         = SyncDist * SyncDist;
                    SyncBufferedDistSqr = SyncDistSqr + 250000;
                    if (Enforced.Debug >= 2)
                    {
                        Log.Line($"SyncDistSqr:{SyncDistSqr} - SyncBufferedDistSqr:{SyncBufferedDistSqr} - DistNorm:{SyncDist}");
                    }
                }
                else
                {
                    SyncDist            = MyAPIGateway.Session.SessionSettings.ViewDistance;
                    SyncDistSqr         = SyncDist * SyncDist;
                    SyncBufferedDistSqr = SyncDistSqr + 250000;
                    if (Enforced.Debug >= 2)
                    {
                        Log.Line($"SyncDistSqr:{SyncDistSqr} - SyncBufferedDistSqr:{SyncBufferedDistSqr} - DistNorm:{SyncDist}");
                    }
                }
                WebMonitor();

                if (!IsServer)
                {
                    RequestEnforcement(MyAPIGateway.Multiplayer.MyId);
                }

                foreach (var mod in MyAPIGateway.Session.Mods)
                {
                    if (mod.PublishedFileId == 540003236)
                    {
                        ThyaImages = true;
                    }
                }

                HudNotify = MyAPIGateway.Utilities.CreateNotification("", 2000, "UrlHighlight");;
                if (HandlesInput)
                {
                    MyAPIGateway.Utilities.MessageEntered += ChatMessageSet;
                }

                GenerateButtonMap();
                Settings = new ShieldSettings(this);
            }
            catch (Exception ex) { Log.Line($"Exception in BeforeStart: {ex}"); }
        }
Ejemplo n.º 22
0
        public void CreateHalfExtents(bool forceUpdate = false, bool growOnly = false)
        {
            _oldGridHalfExtents = DsState.State.GridHalfExtents;
            var myAabb       = MyGrid.PositionComp.LocalAABB;
            var shieldGrid   = MyGrid;
            var expandedAabb = myAabb;

            if (ShieldComp.SubGrids.Count > 1)
            {
                foreach (var grid in ShieldComp.SubGrids.Keys)
                {
                    using (grid.Pin())
                    {
                        if (grid == shieldGrid || grid.MarkedForClose)
                        {
                            continue;
                        }
                        var shieldMatrix = shieldGrid.PositionComp.WorldMatrixNormalizedInv;
                        var gQuaternion  = Quaternion.CreateFromRotationMatrix(grid.WorldMatrix);
                        var gOriBBoxD    = new MyOrientedBoundingBox(grid.PositionComp.WorldAABB.Center, grid.PositionComp.LocalAABB.HalfExtents, gQuaternion);
                        gOriBBoxD.Transform(shieldMatrix);
                        expandedAabb.Include(gOriBBoxD.GetAABB());
                    }
                }
            }

            if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield)
            {
                var fortify = DsSet.Settings.FortifyShield ? 3 : 1;
                var fit     = (float)UtilsStatic.GetFit(DsSet.Settings.Fit) * 0.5f;
                var scaler  = 4f;
                if (shieldGrid.GridSizeEnum == MyCubeSize.Small && DsSet.Settings.Fit < 15)
                {
                    scaler = 5;
                }


                var size       = (expandedAabb.HalfExtents.Max() * fortify) * fit;
                var vectorSize = new Vector3D(size, size, size);

                var fudge       = shieldGrid.GridSize * scaler;
                var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - vectorSize.LengthSquared();
                if (extentsDiff < -1 || extentsDiff > 1 || DsState.State.GridHalfExtents == Vector3D.Zero || !fudge.Equals(DsState.State.ShieldFudge))
                {
                    DsState.State.GridHalfExtents = vectorSize;
                }
                DsState.State.ShieldFudge = fudge;
            }
            else
            {
                var offset = MyGrid.GridSize * 0.01;
                DsState.State.ShieldFudge = 0f;
                var extentsDiff = DsState.State.GridHalfExtents.Length() - expandedAabb.HalfExtents.Length();
                var overThreshold = extentsDiff <-offset || extentsDiff> offset || forceUpdate;   //first grow, second shrink
                if (overThreshold || DsState.State.GridHalfExtents == Vector3D.Zero)
                {
                    DsState.State.GridHalfExtents = expandedAabb.HalfExtents;
                }
            }
            _halfExtentsChanged = !DsState.State.GridHalfExtents.Equals(_oldGridHalfExtents) || (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) && SettingsUpdated;

            if (_halfExtentsChanged || SettingsUpdated)
            {
                _adjustShape = true;
            }
        }
Ejemplo n.º 23
0
        public override void BeforeStart()
        {
            try
            {
                MpActive        = MyAPIGateway.Multiplayer.MultiplayerActive;
                IsServer        = MyAPIGateway.Multiplayer.IsServer;
                DedicatedServer = MyAPIGateway.Utilities.IsDedicated;

                var env = MyDefinitionManager.Static.EnvironmentDefinition;
                if (env.LargeShipMaxSpeed > MaxEntitySpeed)
                {
                    MaxEntitySpeed = env.LargeShipMaxSpeed;
                }
                else if (env.SmallShipMaxSpeed > MaxEntitySpeed)
                {
                    MaxEntitySpeed = env.SmallShipMaxSpeed;
                }

                Log.Init("debugdevelop.log");
                Log.Line($"Logging Started: Server:{IsServer} - Dedicated:{DedicatedServer} - MpActive:{MpActive}");

                MyAPIGateway.Session.DamageSystem.RegisterBeforeDamageHandler(0, CheckDamage);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdShieldHit, ShieldHitReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdEnforce, EnforcementReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdO2GeneratorSettings, O2GeneratorSettingsReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdControllerState, ControllerStateReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdControllerSettings, ControllerSettingsReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdModulatorSettings, ModulatorSettingsReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdModulatorState, ModulatorStateReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdEnhancerState, EnhancerStateReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdO2GeneratorState, O2GeneratorStateReceived);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PacketIdEmitterState, EmitterStateReceived);

                if (!MpActive)
                {
                    Players.TryAdd(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.Player);
                }
                MyEntities.OnEntityRemove += OnEntityRemove;

                MyVisualScriptLogicProvider.PlayerDisconnected   += PlayerDisconnected;
                MyVisualScriptLogicProvider.PlayerRespawnRequest += PlayerConnected;
                if (!DedicatedServer)
                {
                    MyAPIGateway.TerminalControls.CustomControlGetter += CustomControls;
                }

                if (IsServer)
                {
                    Log.Line("LoadConf - Session: This is a server");
                    UtilsStatic.PrepConfigFile();
                    UtilsStatic.ReadConfigFile();
                }

                if (MpActive)
                {
                    SyncDist            = MyAPIGateway.Session.SessionSettings.SyncDistance;
                    SyncDistSqr         = SyncDist * SyncDist;
                    SyncBufferedDistSqr = SyncDistSqr + 250000;
                    if (Enforced.Debug >= 2)
                    {
                        Log.Line($"SyncDistSqr:{SyncDistSqr} - SyncBufferedDistSqr:{SyncBufferedDistSqr} - DistNorm:{SyncDist}");
                    }
                }
                else
                {
                    SyncDist            = MyAPIGateway.Session.SessionSettings.ViewDistance;
                    SyncDistSqr         = SyncDist * SyncDist;
                    SyncBufferedDistSqr = SyncDistSqr + 250000;
                    if (Enforced.Debug >= 2)
                    {
                        Log.Line($"SyncDistSqr:{SyncDistSqr} - SyncBufferedDistSqr:{SyncBufferedDistSqr} - DistNorm:{SyncDist}");
                    }
                }
                MyAPIGateway.Parallel.StartBackground(WebMonitor);
            }
            catch (Exception ex) { Log.Line($"Exception in BeforeStart: {ex}"); }
        }
Ejemplo n.º 24
0
        private void ComputeCap()
        {
            _updateCap = false;

            if (ShieldComp.SubGrids.Count == 0)
            {
                UpdateSubGrids();
                if (ShieldComp.SubGrids.Count == 0)
                {
                    Log.Line($"SubGrids remained 0 in ComputeCap");
                    return;
                }
            }

            Vector3I center = Vector3I.Zero;

            foreach (var sub in ShieldComp.SubGrids.Keys)
            {
                var isRootGrid        = sub == MyGrid;
                var subWorldCenter    = sub.GridIntegerToWorld(Vector3I.Zero);
                var parentLocalOffset = MyGrid.WorldToGridInteger(subWorldCenter);

                foreach (var cube in sub.GetFatBlocks())
                {
                    var term        = cube as IMyTerminalBlock;
                    var sensor      = cube as IMySensorBlock;
                    var camera      = cube as IMyCameraBlock;
                    var light       = cube as IMyLightingBlock;
                    var sound       = cube as IMySoundBlock;
                    var buttonPanel = term != null && cube.BlockDefinition != null && cube.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_TerminalBlock);
                    if (buttonPanel || term == null || sensor != null || sound != null || camera != null || light != null)
                    {
                        continue;
                    }
                    Vector3I translatedPos;

                    if (!isRootGrid)
                    {
                        translatedPos = cube.Position + parentLocalOffset;
                    }
                    else
                    {
                        translatedPos = cube.Position;
                    }

                    center += translatedPos;

                    _capcubeBoxList.Add(new CapCube {
                        Cube = cube, Position = translatedPos
                    });
                }
            }

            BoundingBox newBox = BoundingBox.Invalid;

            var totalBlockCnt = _capcubeBoxList.Count;
            var unitLen       = MyGrid.GridSize;

            center /= totalBlockCnt;
            var percentile95Th = (int)(totalBlockCnt * 0.12);

            ShellSort(_capcubeBoxList, center);
            _capcubeBoxList.RemoveRange(totalBlockCnt - percentile95Th, percentile95Th);

            for (int i = 0; i < _capcubeBoxList.Count; i++)
            {
                var cap = _capcubeBoxList[i];
                newBox.Min = Vector3.Min(newBox.Min, cap.Cube.Min);
                newBox.Max = Vector3.Max(newBox.Max, cap.Cube.Max);
            }

            newBox.Min *= MyGrid.GridSize;
            newBox.Max *= MyGrid.GridSize;

            _capcubeBoxList.Clear();

            var boxsArea = newBox.SurfaceArea();

            if (boxsArea < 1)
            {
                boxsArea = (float)UtilsStatic.SurfaceAreaCuboid(totalBlockCnt * unitLen, unitLen, unitLen);
            }

            var surfaceArea = (float)Math.Sqrt(boxsArea);

            DsState.State.GridIntegrity = (surfaceArea * MagicCapRatio);
        }
Ejemplo n.º 25
0
 public Session()
 {
     UiInput = new UiInput(this);
     UtilsStatic.UnitSphereRandomOnly(ref LosPointSphere);
 }
Ejemplo n.º 26
0
        public override void BeforeStart()
        {
            try
            {
                MpActive        = MyAPIGateway.Multiplayer.MultiplayerActive;
                IsServer        = MyAPIGateway.Multiplayer.IsServer;
                DedicatedServer = MyAPIGateway.Utilities.IsDedicated;

                var env = MyDefinitionManager.Static.EnvironmentDefinition;
                if (env.LargeShipMaxSpeed > MaxEntitySpeed)
                {
                    MaxEntitySpeed = env.LargeShipMaxSpeed;
                }
                else if (env.SmallShipMaxSpeed > MaxEntitySpeed)
                {
                    MaxEntitySpeed = env.SmallShipMaxSpeed;
                }

                Log.Init("debugdevelop.log");
                Log.Line($"Logging Started: Server:{IsServer} - Dedicated:{DedicatedServer} - MpActive:{MpActive}");

                MyAPIGateway.Session.DamageSystem.RegisterBeforeDamageHandler(0, CheckDamage);
                MyAPIGateway.Multiplayer.RegisterMessageHandler(PACKET_ID, ReceivedPacket);

                if (!DedicatedServer && IsServer)
                {
                    Players.TryAdd(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.Player);
                }
                MyEntities.OnEntityRemove                        += OnEntityRemove;
                MyAPIGateway.Session.OnSessionReady              += OnSessionReady;
                MyVisualScriptLogicProvider.PlayerDisconnected   += PlayerDisconnected;
                MyVisualScriptLogicProvider.PlayerRespawnRequest += PlayerConnected;
                if (!DedicatedServer)
                {
                    MyAPIGateway.TerminalControls.CustomControlGetter += CustomControls;
                }

                if (IsServer)
                {
                    Log.Line("LoadConf - Session: This is a server");
                    UtilsStatic.PrepConfigFile();
                    UtilsStatic.ReadConfigFile();
                }

                if (MpActive)
                {
                    SyncDist            = MyAPIGateway.Session.SessionSettings.SyncDistance;
                    SyncDistSqr         = SyncDist * SyncDist;
                    SyncBufferedDistSqr = SyncDistSqr + 250000;
                    if (Enforced.Debug >= 2)
                    {
                        Log.Line($"SyncDistSqr:{SyncDistSqr} - SyncBufferedDistSqr:{SyncBufferedDistSqr} - DistNorm:{SyncDist}");
                    }
                }
                else
                {
                    SyncDist            = MyAPIGateway.Session.SessionSettings.ViewDistance;
                    SyncDistSqr         = SyncDist * SyncDist;
                    SyncBufferedDistSqr = SyncDistSqr + 250000;
                    if (Enforced.Debug >= 2)
                    {
                        Log.Line($"SyncDistSqr:{SyncDistSqr} - SyncBufferedDistSqr:{SyncBufferedDistSqr} - DistNorm:{SyncDist}");
                    }
                }
                MyAPIGateway.Parallel.StartBackground(WebMonitor);

                if (!IsServer)
                {
                    RequestEnforcement(MyAPIGateway.Multiplayer.MyId);
                }

                foreach (var mod in MyAPIGateway.Session.Mods)
                {
                    if (mod.PublishedFileId == 540003236)
                    {
                        ThyaImages = true;
                    }
                }

                ApiServer.Load();
            }
            catch (Exception ex) { Log.Line($"Exception in BeforeStart: {ex}"); }
        }
Ejemplo n.º 27
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                if (!EntityAlive())
                {
                    return;
                }
                if (!ShieldOn())
                {
                    //if (Session.Enforced.Debug == 3 && WasOnline) Log.Line($"Off: WasOn:{WasOnline} - Online:{DsState.State.Online}({_prevShieldActive}) - Lowered:{DsState.State.Lowered} - ShieldCharge:{DsState.State.Charge} - Sus:{DsState.State.Suspended} - EW:{DsState.State.EmitterWorking} - Perc:{DsState.State.ShieldPercent} - Wake:{DsState.State.Waking} - ShieldId [{Shield.EntityId}]");
                    if (WasOnline)
                    {
                        OfflineShield();
                    }
                    else if (DsState.State.Message)
                    {
                        ShieldChangeState();
                    }
                    return;
                }
                if (DsState.State.Online)
                {
                    if (_comingOnline)
                    {
                        ComingOnlineSetup();
                    }
                    if (_isServer)
                    {
                        var createHeTiming = _count == 6 && (_lCount == 1 || _lCount == 6);
                        if (GridIsMobile && createHeTiming)
                        {
                            CreateHalfExtents();
                        }
                        if (_syncEnts)
                        {
                            SyncThreadedEnts();
                        }

                        if (_mpActive && (_forceBufferSync || _count == 29))
                        {
                            var newPercentColor = UtilsStatic.GetShieldColorFromFloat(DsState.State.ShieldPercent);
                            if (_forceBufferSync || newPercentColor != _oldPercentColor)
                            {
                                ShieldChangeState();
                                _oldPercentColor = newPercentColor;
                                _forceBufferSync = false;
                            }
                            else if (_lCount == 7 && _eCount == 7)
                            {
                                ShieldChangeState();
                            }
                        }
                    }
                    else if (_syncEnts)
                    {
                        SyncThreadedEnts();
                    }
                    if (!_isDedicated && (_tick60 || Session.Instance.HudIconReset))
                    {
                        HudCheck();
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in UpdateBeforeSimulation: {ex}"); }
        }
Ejemplo n.º 28
0
        public void AbsorbEmp()
        {
            if (Vector3D.DistanceSquared(DetectionCenter, Session.Instance.EmpWork.EpiCenter) <= Session.Instance.EmpWork.RangeCapSqr)
            {
                var        empResistenceRatio    = 1f;
                const long AttackerId            = 0L;
                var        energyResistenceRatio = DsState.State.ModulateKinetic;
                var        epiCenter             = Session.Instance.EmpWork.EpiCenter;
                var        rangeCap    = Session.Instance.EmpWork.RangeCap;
                var        empDirYield = Session.Instance.EmpWork.DirYield;

                if (DsState.State.EmpProtection)
                {
                    if (energyResistenceRatio < 0.4)
                    {
                        energyResistenceRatio = 0.4f;
                    }
                    empResistenceRatio = 0.1f;
                }
                //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - Start] ShieldOwner:{MyGrid.DebugName} - Yield:{warHeadYield} - StackCount:{stackCount} - ProtectionRatio:{energyResistenceRatio * empResistenceRatio} - epiCenter:{epiCenter}");
                var line      = new LineD(epiCenter, SOriBBoxD.Center);
                var testDir   = Vector3D.Normalize(line.From - line.To);
                var ray       = new RayD(line.From, -testDir);
                var ellipsoid = CustomCollision.IntersectEllipsoid(DetectMatrixOutsideInv, DetectionMatrix, ray);
                if (!ellipsoid.HasValue)
                {
                    //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - Ellipsoid null hit] ShieldOwner:{MyGrid.DebugName} - Yield:{warHeadYield} - StackCount:{stackCount} - ProtectionRatio:{energyResistenceRatio * empResistenceRatio} - epiCenter:{epiCenter}");
                    return;
                }
                var      impactPos = line.From + (testDir * -ellipsoid.Value);
                IHitInfo hitInfo;
                MyAPIGateway.Physics.CastRay(epiCenter, impactPos, out hitInfo, CollisionLayers.DefaultCollisionLayer);
                if (hitInfo != null)
                {
                    //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - occluded] ShieldOwner:{MyGrid.DebugName} - by {((MyEntity)hitInfo.HitEntity).DebugName}");
                    return;
                }
                var gridLocalMatrix    = MyGrid.PositionComp.LocalMatrix;
                var worldDirection     = impactPos - gridLocalMatrix.Translation;
                var localPosition      = Vector3D.TransformNormal(worldDirection, MatrixD.Transpose(gridLocalMatrix));
                var hitFaceSurfaceArea = UtilsStatic.GetIntersectingSurfaceArea(ShieldShapeMatrix, localPosition);

                var invSqrDist   = UtilsStatic.InverseSqrDist(epiCenter, impactPos, rangeCap);
                var damageScaler = invSqrDist * hitFaceSurfaceArea;
                if (invSqrDist <= 0)
                {
                    //if (Session.Enforced.Debug >= 2) Log.Line($"[EmpBlastShield - Range] ShieldOwner:{MyGrid.DebugName} - insqrDist was 0");
                    return;
                }

                var targetDamage = (float)(((empDirYield * damageScaler) * energyResistenceRatio) * empResistenceRatio);

                if (targetDamage >= DsState.State.Charge * ConvToHp)
                {
                    _empOverLoad = true;
                }
                //if (Session.Enforced.Debug >= 2) Log.Line($"-----------------------] epiDist:{Vector3D.Distance(epiCenter, impactPos)} - iSqrDist:{invSqrDist} - RangeCap:{rangeCap} - SurfaceA:{hitFaceSurfaceArea}({_ellipsoidSurfaceArea * 0.5}) - dirYield:{empDirYield} - damageScaler:{damageScaler} - Damage:{targetDamage}(toOver:{(targetDamage / (DsState.State.Charge * ConvToHp))})");

                if (_isServer && _mpActive)
                {
                    AddEmpBlastHit(AttackerId, targetDamage, Session.Instance.MPEMP, impactPos);
                }

                EnergyHit           = HitType.Energy;
                WorldImpactPosition = epiCenter;
                Absorb += targetDamage;
            }
        }
Ejemplo n.º 29
0
        private void Timings()
        {
            Tick     = (uint)(Session.ElapsedPlayTime.TotalMilliseconds * TickTimeDiv);
            Tick10   = Tick % 10 == 0;
            Tick20   = Tick % 20 == 0;
            Tick30   = Tick % 30 == 0;
            Tick60   = Tick % 60 == 0;
            Tick60   = Tick % 60 == 0;
            Tick180  = Tick % 120 == 0;
            Tick180  = Tick % 180 == 0;
            Tick300  = Tick % 300 == 0;
            Tick600  = Tick % 600 == 0;
            Tick1800 = Tick % 1800 == 0;

            if (Tick10 && RingOverFlows > 0)
            {
                RingOverFlows--;
            }

            if (_count++ == 59)
            {
                _count = 0;
                _lCount++;
                if (_lCount == 10)
                {
                    _lCount = 0;
                    _eCount++;
                    if (_eCount == 10)
                    {
                        _eCount        = 0;
                        _previousEntId = -1;
                    }
                }
            }
            if (!GameLoaded)
            {
                if (!MiscLoaded)
                {
                    if (SessionReady && GlobalProtect.Count > 0 && (IsServer || !IsServer && ClientLoadCount++ > 120))
                    {
                        UtilsStatic.GetDefinitons();
                        if (!IsServer)
                        {
                            Players.TryAdd(MyAPIGateway.Session.Player.IdentityId, MyAPIGateway.Session.Player);
                        }
                        Api.Init();
                        MiscLoaded = true;
                        GameLoaded = true;

                        if (!string.IsNullOrEmpty(PlayerMessage))
                        {
                            MyAPIGateway.Utilities.ShowNotification(PlayerMessage, 10000, "White");
                        }
                    }
                }
            }

            if (!PlayersLoaded && KeenFuckery())
            {
                PlayersLoaded = true;
            }

            if (Tick20)
            {
                Scale();
                EntSlotTick = Tick % (180 / EntSlotScaler) == 0;
                if (EntSlotTick || FastRefresh)
                {
                    LoadBalancer();
                }
            }
            else
            {
                EntSlotTick = false;
            }
        }
Ejemplo n.º 30
0
        private void BlockMoveAnimation()
        {
            var percent = ShieldComp.DefenseShields.DsState.State.ShieldPercent;

            if (EmiState.State.Compact)
            {
                if (_count == 0)
                {
                    EmissiveIntensity = 2;
                }
                if (_count < 30)
                {
                    EmissiveIntensity += 1;
                }
                else
                {
                    EmissiveIntensity -= 1;
                }
                MyCube.SetEmissiveParts(PlasmaEmissive, UtilsStatic.GetShieldColorFromFloat(percent), 0.1f * EmissiveIntensity);
                return;
            }

            if (_subpartRotor.Closed.Equals(true))
            {
                BlockMoveAnimationReset(false);
            }
            RotationTime -= 1;
            if (AnimationLoop == 0)
            {
                TranslationTime = 0;
            }
            if (AnimationLoop < 299)
            {
                TranslationTime += 1;
            }
            else
            {
                TranslationTime -= 1;
            }
            if (_count == 0)
            {
                EmissiveIntensity = 2;
            }
            if (_count < 30)
            {
                EmissiveIntensity += 1;
            }
            else
            {
                EmissiveIntensity -= 1;
            }

            var rotationMatrix = MatrixD.CreateRotationY(0.025f * RotationTime);
            var matrix         = rotationMatrix * MatrixD.CreateTranslation(0, Definition.BlockMoveTranslation * TranslationTime, 0);

            _subpartRotor.PositionComp.LocalMatrix = matrix;
            _subpartRotor.SetEmissiveParts(PlasmaEmissive, UtilsStatic.GetShieldColorFromFloat(percent), 0.1f * EmissiveIntensity);

            if (AnimationLoop++ == 599)
            {
                AnimationLoop = 0;
            }
        }