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}"); } }
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}]"); } }
private void StorageSetup() { try { var isServer = MyAPIGateway.Multiplayer.IsServer; if (DsSet == null) { DsSet = new ControllerSettings(Shield); } if (DsState == null) { DsState = new ControllerState(Shield); } if (Shield.Storage == null) { DsState.StorageInit(); } if (!isServer) { var enforcement = Enforcements.LoadEnforcement(Shield); if (enforcement != null) { Session.Enforced = enforcement; } } DsSet.LoadSettings(); if (!DsState.LoadState() && !isServer) { _clientNotReady = true; } UpdateSettings(DsSet.Settings); if (isServer) { if (DsSet.Settings.Fit > 22) { DsSet.Settings.Fit = 22; } DsState.State.Overload = false; DsState.State.NoPower = false; DsState.State.Remodulate = false; if (DsState.State.Suspended) { DsState.State.Suspended = false; DsState.State.Online = false; } DsState.State.Sleeping = false; DsState.State.Waking = false; DsState.State.FieldBlocked = false; DsState.State.GridHalfExtents = Vector3D.Zero; DsState.State.Heat = 0; } } catch (Exception ex) { Log.Line($"Exception in StorageSetup: {ex}"); } }
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"); } }
private bool RequestEnforcement() { if (Session.Enforced.Version <= 0) { if (!_isServer) { var enforcement = Enforcements.LoadEnforcement(Shield); if (enforcement != null) { Session.Enforced = enforcement; } else if (!_requestedEnforcement) { Enforcements.EnforcementRequest(Shield.EntityId); _requestedEnforcement = true; } } } return(Session.Enforced.Version <= 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}"); } }