private void SerializeRopeData(BitStream stream, bool applyWhenReading, List <MyCubeGrid> gridsGroup = null) { if (MyRopeComponent.Static == null) { return; } if (stream.Writing) { m_tmpRopes.Clear(); m_tmpRopeGrids.Clear(); m_tmpRopeGrids.Add(Entity); Debug.Assert(gridsGroup != null); if (gridsGroup != null) { foreach (var grid in gridsGroup) { m_tmpRopeGrids.Add(grid); } } MyRopeComponent.Static.GetRopesForGrids(m_tmpRopeGrids, m_tmpRopes); MyRopeData ropeData; stream.WriteUInt16((ushort)m_tmpRopes.Count); foreach (var rope in m_tmpRopes) { var ropeProxyTarget = MyMultiplayer.Static.ReplicationLayer.GetProxyTarget((IMyEventProxy)rope); NetworkId ropeNetworkId = MyMultiplayer.Static.ReplicationLayer.GetNetworkIdByObject(ropeProxyTarget); stream.WriteNetworkId(ropeNetworkId); //TODO - MyRopeComponent should be rewritten to singleton MyRopeComponent.GetRopeData(rope.EntityId, out ropeData); stream.WriteFloat(ropeData.CurrentRopeLength); } m_tmpRopes.Clear(); m_tmpRopeGrids.Clear(); } else { uint ropesCount = stream.ReadUInt16(); for (uint i = 0; i < ropesCount; ++i) { NetworkId ropeNetworkId = stream.ReadNetworkId(); float ropeLength = stream.ReadFloat(); MyRopeReplicable replicable = MyMultiplayer.Static.ReplicationLayer.GetObjectByNetworkId(ropeNetworkId) as MyRopeReplicable; MyRope rope = replicable != null ? replicable.Instance : null; if (rope != null && applyWhenReading) { MyRopeComponent.Static.SetRopeLengthSynced(rope.EntityId, ropeLength); } } } }
public override void AddRenderObjects() { MyRopeData data; MyRopeComponent.GetRopeData(Container.Entity.EntityId, out data); Debug.Assert(data.Definition.ColorMetalTexture != null); Debug.Assert(data.Definition.NormalGlossTexture != null); Debug.Assert(data.Definition.AddMapsTexture != null); SetRenderObjectID(0, MyRenderProxy.CreateLineBasedObject( data.Definition.ColorMetalTexture, data.Definition.NormalGlossTexture, data.Definition.AddMapsTexture)); }
public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false) { var ob = (MyObjectBuilder_Rope)base.GetObjectBuilder(copy); MyRopeData data; MyRopeComponent.GetRopeData(EntityId, out data); ob.MaxRopeLength = data.MaxRopeLength; ob.CurrentRopeLength = data.CurrentRopeLength; ob.EntityIdHookA = data.HookEntityIdA; ob.EntityIdHookB = data.HookEntityIdB; ob.SubtypeName = data.Definition.Id.SubtypeName; return(ob); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { base.Init(objectBuilder); var ob = (MyObjectBuilder_Rope)objectBuilder; var ropeDefinitionId = new MyDefinitionId(typeof(MyObjectBuilder_RopeDefinition), ob.SubtypeName ?? "BasicRope"); var ropeDefinition = MyDefinitionManager.Static.GetRopeDefinition(ropeDefinitionId); MyRopeComponent.AddRopeData(new MyRopeData { HookEntityIdA = ob.EntityIdHookA, HookEntityIdB = ob.EntityIdHookB, MaxRopeLength = ob.MaxRopeLength, CurrentRopeLength = ob.CurrentRopeLength, Definition = ropeDefinition, }, ob.EntityId); }
public void OnUse(long hookIdTarget) { bool flag = false; MyEntity entity = null; if (MyEntities.TryGetEntityById(hookIdTarget, out entity, false)) { if (hookIdTarget != this.m_hookIdFrom) { if (this.m_hookIdFrom == 0) { this.m_hookIdFrom = hookIdTarget; entity.OnClosing += this.m_selectedHook_OnClosing; flag = true; } else if (MyRopeComponent.HasRope(this.m_hookIdFrom)) { this.m_hookIdFrom = hookIdTarget; flag = true; } else { if (MyRopeComponent.CanConnectHooks(this.m_hookIdFrom, hookIdTarget, this.m_ropeDefinition)) { MyRopeComponent.AddRopeRequest(this.m_hookIdFrom, hookIdTarget, this.m_ropeDefinition.Id); flag = true; } this.Clear(); } } MySoundPair soundId = flag ? this.m_ropeDefinition.AttachSound : null; if (soundId != null) { MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter(); if (emitter != null) { emitter.SetPosition(new Vector3D?(entity.PositionComp.GetPosition())); bool?nullable = null; emitter.PlaySound(soundId, false, false, false, false, false, nullable); } } } }
public override void OnDestroy() { MyRopeComponent.RemoveRopeData(Instance.EntityId); base.OnDestroy(); }