public void SendStateToClients(WarpEffectUpdate.State state, long gridSystemId, long gridId, float gridRadius) { try { // Send info to all players, they can ignore the data if they wish byte [] data = MyAPIGateway.Utilities.SerializeToBinary(new WarpEffectUpdate(state, gridSystemId, gridId, gridRadius)); MyAPIGateway.Multiplayer.SendMessageToOthers(packetEffectState, data); if (MyAPIGateway.Session.Player != null) // The server is also a client { PerformStateUpdate(state, gridSystemId, gridId, gridRadius); } } catch { } }
private void PerformStateUpdate(WarpEffectUpdate.State state, long gridSystemId, long gridId, float gridRadius) { if (state == WarpEffectUpdate.State.Destroy) { warpEffects.Remove(gridSystemId); } else { IMyCubeGrid grid = MyAPIGateway.Entities.GetEntityById(gridId) as IMyCubeGrid; if (grid == null && state != WarpEffectUpdate.State.HardStop && state != WarpEffectUpdate.State.SoftStop) { return; } WarpEffects effect; if (!warpEffects.TryGetValue(gridSystemId, out effect)) { effect = new WarpEffects(); warpEffects [gridSystemId] = effect; } switch (state) { case WarpEffectUpdate.State.Charging: effect.PlayCharging(grid); return; case WarpEffectUpdate.State.InWarp: effect.PlayInWarp(grid, gridRadius); return; case WarpEffectUpdate.State.StopWarp: effect.PlayStopWarp(grid); return; case WarpEffectUpdate.State.HardStop: effect.FullStop(); return; case WarpEffectUpdate.State.SoftStop: effect.FullStop(false); return; } } }