Example #1
0
        public override void UpdateOnceBeforeFrame()
        {
            base.UpdateOnceBeforeFrame();
            try
            {
                if (Shield.CubeGrid.Physics == null)
                {
                    return;
                }
                _isServer    = Session.Instance.IsServer;
                _isDedicated = Session.Instance.DedicatedServer;
                _mpActive    = Session.Instance.MpActive;

                PowerInit();
                MyAPIGateway.Session.OxygenProviderSystem.AddOxygenGenerator(_ellipsoidOxyProvider);

                if (_isServer)
                {
                    Enforcements.SaveEnforcement(Shield, Session.Enforced, true);
                }
                else
                {
                    Session.Instance.FunctionalShields[this] = false;
                }

                Session.Instance.Controllers.Add(this);
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"UpdateOnceBeforeFrame: ShieldId [{Shield.EntityId}]");
                }
            }
            catch (Exception ex) { Log.Line($"Exception in Controller UpdateOnceBeforeFrame: {ex}"); }
        }
Example #2
0
        private void BeforeInit()
        {
            if (Shield.CubeGrid.Physics == null)
            {
                return;
            }
            _isServer    = Session.Instance.IsServer;
            _isDedicated = Session.Instance.DedicatedServer;
            _mpActive    = Session.Instance.MpActive;

            PowerInit();
            MyAPIGateway.Session.OxygenProviderSystem.AddOxygenGenerator(_ellipsoidOxyProvider);

            if (_isServer)
            {
                Enforcements.SaveEnforcement(Shield, Session.Enforced, true);
            }

            Session.Instance.FunctionalShields[this] = false;
            Session.Instance.Controllers.Add(this);

            //if (MyAPIGateway.Session.CreativeMode) CreativeModeWarning();
            IsWorking    = MyCube.IsWorking;
            IsFunctional = MyCube.IsFunctional;
            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            InitTick     = Session.Instance.Tick;
            _bTime       = 1;
            _bInit       = true;
            if (Session.Enforced.Debug == 3)
            {
                Log.Line($"UpdateOnceBeforeFrame: ShieldId [{Shield.EntityId}]");
            }
        }
Example #3
0
        private void BeforeInit()
        {
            if (Shield.CubeGrid.Physics == null)
            {
                return;
            }
            _isServer    = Session.Instance.IsServer;
            _isDedicated = Session.Instance.DedicatedServer;
            _mpActive    = Session.Instance.MpActive;

            PowerInit();
            MyAPIGateway.Session.OxygenProviderSystem.AddOxygenGenerator(_ellipsoidOxyProvider);

            if (_isServer)
            {
                Enforcements.SaveEnforcement(Shield, Session.Enforced, true);
            }

            Session.Instance.FunctionalShields[this] = false;
            Session.Instance.Controllers.Add(this);

            //if (MyAPIGateway.Session.CreativeMode) CreativeModeWarning();
            IsWorking    = MyCube.IsWorking;
            IsFunctional = MyCube.IsFunctional;
            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            InitTick     = Session.Instance.Tick;
            _bTime       = 1;
            _bInit       = true;
            if (Session.Enforced.Debug == 3)
            {
                Log.Line($"UpdateOnceBeforeFrame: ShieldId [{Shield.EntityId}]");
            }

            if (!_isDedicated)
            {
                _alertAudio = new MyEntity3DSoundEmitter(null, true, 1f);

                _audioReInit    = new MySoundPair("Arc_reinitializing");
                _audioSolidBody = new MySoundPair("Arc_solidbody");
                _audioOverload  = new MySoundPair("Arc_overloaded");
                _audioEmp       = new MySoundPair("Arc_EMP");
                _audioRemod     = new MySoundPair("Arc_remodulating");
                _audioLos       = new MySoundPair("Arc_noLOS");
                _audioNoPower   = new MySoundPair("Arc_insufficientpower");
            }
        }
Example #4
0
        private static void EnforcementReceived(byte[] bytes)
        {
            try
            {
                if (bytes.Length <= 2)
                {
                    return;
                }

                var data = MyAPIGateway.Utilities.SerializeFromBinary <DataEnforce>(bytes); // this will throw errors on invalid data

                if (data == null)
                {
                    return;
                }

                IMyEntity ent;
                if (!MyAPIGateway.Entities.TryGetEntityById(data.EntityId, out ent) || ent.Closed)
                {
                    Log.Line($"EnforceData Received; {data.Type}; {(ent == null ? "can't find entity" : (ent.Closed ? "found closed entity" : "entity not a shield"))}");
                    return;
                }

                var logic = ent.GameLogic.GetAs <DefenseShields>();
                if (logic == null)
                {
                    return;
                }

                switch (data.Type)
                {
                case PacketType.Enforce:
                {
                    if (data.Enforce == null)
                    {
                        return;
                    }

                    if (Enforced.Debug >= 3)
                    {
                        Log.Line($"EnforceData Received; Enforce - Server:\n{data.Enforce}");
                    }
                    if (!MyAPIGateway.Multiplayer.IsServer)
                    {
                        Enforcements.SaveEnforcement(logic.Shield, data.Enforce);
                        EnforceInit = true;
                        if (Enforced.Debug >= 3)
                        {
                            Log.Line("client accepted enforcement");
                        }
                        if (Enforced.Debug >= 3)
                        {
                            Log.Line($"Client EnforceInit Complete with enforcements:\n{data.Enforce}");
                        }
                    }
                    else
                    {
                        PacketizeEnforcements(logic.Shield, data.Enforce.SenderId);
                    }
                }
                break;
                }
            }
            catch (Exception ex) { Log.Line($"Exception in PacketEnforcementReceived: {ex}"); }
        }