protected override void UnloadData() { //Debug.Assert(m_instance == this); m_instance = null; base.UnloadData(); }
public void DeleteFloatingObject(MyFloatingObject floatingObject) { if (floatingObject != null) { MyFloatingObjects.RemoveFloatingObject(floatingObject, true); this.Deactivate(); } }
protected override void UnloadData() { //Debug.Assert(m_instance == this); m_instance = null; m_stableObjectsClient.Clear(); base.UnloadData(); }
public override void LoadData() { base.LoadData(); Debug.Assert(m_instance == null); m_instance = this; m_measurementTime = new Stopwatch(); m_measurementTime.Start(); }
public void CutFloatingObject(MyFloatingObject floatingObject) { if (floatingObject == null) { return; } CopyfloatingObject(floatingObject); MyFloatingObjects.RemoveFloatingObject(floatingObject, true); Deactivate(); }
public override void LoadData() { base.LoadData(); Debug.Assert(m_instance == null); m_instance = this; SyncObject = new MySyncFloatingObjects(); m_measurementTime = new Stopwatch(); m_measurementTime.Start(); }
public static MyEntity Spawn(MyPhysicalItemDefinition itemDefinition, Vector3D translation, Vector3D forward, Vector3D up, int amount = 1, float scale = 1) { var objectBuilder = MyObjectBuilderSerializer.CreateNewObject(itemDefinition.Id.TypeId, itemDefinition.Id.SubtypeName) as MyObjectBuilder_PhysicalObject; var floatingObj = MyFloatingObjects.Spawn( new MyPhysicalInventoryItem((MyFixedPoint)amount, objectBuilder, scale), translation, forward, up); return(floatingObj); }
internal static void UnregisterFloatingObject(MyFloatingObject obj) { if (obj.VoxelMaterial != null) { m_floatingOres.Remove(obj); } else { m_floatingItems.Remove(obj); } if (Sync.IsServer) { MyFloatingObjects.RemoveFromSynchronization(obj); } obj.WasRemovedFromWorld = true; }
private void ChangeClipboardPreview(bool visible) { if ((this.m_copiedFloatingObjects.Count == 0) || !visible) { foreach (MyFloatingObject local1 in this.m_previewFloatingObjects) { Vector4? color = null; Vector3? inflateAmount = null; MyStringId?lineMaterial = null; Sandbox.Game.Entities.MyEntities.EnableEntityBoundingBoxDraw(local1, false, color, 0.01f, inflateAmount, lineMaterial); local1.Close(); } this.m_previewFloatingObjects.Clear(); this.m_visible = false; } else { Sandbox.Game.Entities.MyEntities.RemapObjectBuilderCollection((IEnumerable <MyObjectBuilder_EntityBase>) this.m_copiedFloatingObjects); using (List <MyObjectBuilder_FloatingObject> .Enumerator enumerator2 = this.m_copiedFloatingObjects.GetEnumerator()) { while (enumerator2.MoveNext()) { MyFloatingObject floatingObject = Sandbox.Game.Entities.MyEntities.CreateFromObjectBuilder(enumerator2.Current, false) as MyFloatingObject; if (floatingObject == null) { this.ChangeClipboardPreview(false); break; } this.MakeTransparent(floatingObject); this.IsActive = visible; this.m_visible = visible; Sandbox.Game.Entities.MyEntities.Add(floatingObject, true); MyFloatingObjects.UnregisterFloatingObject(floatingObject); floatingObject.Save = false; this.DisablePhysicsRecursively(floatingObject); this.m_previewFloatingObjects.Add(floatingObject); } } } }
public bool PasteFloatingObject(MyInventory buildInventory = null) { if (this.m_copiedFloatingObjects.Count == 0) { return(false); } if ((this.m_copiedFloatingObjects.Count > 0) && !this.IsActive) { if (this.CheckPastedFloatingObjects()) { this.Activate(); } else { MyHud.Notifications.Add(MyNotificationSingletons.CopyPasteBlockNotAvailable); MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); } return(true); } if (!this.m_canBePlaced) { MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); return(false); } MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceItem); Sandbox.Game.Entities.MyEntities.RemapObjectBuilderCollection((IEnumerable <MyObjectBuilder_EntityBase>) this.m_copiedFloatingObjects); bool flag = false; int num = 0; foreach (MyObjectBuilder_FloatingObject local1 in this.m_copiedFloatingObjects) { local1.PersistentFlags = MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; local1.PositionAndOrientation = new MyPositionAndOrientation(this.m_previewFloatingObjects[num].WorldMatrix); num++; MyFloatingObjects.RequestSpawnCreative(local1); flag = true; } this.Deactivate(); return(flag); }
internal static void RegisterFloatingObject(MyFloatingObject obj) { Debug.Assert(obj != null && obj.Item.Amount > 0, "Object cannot be null and amount must be > 0"); if (obj.WasRemovedFromWorld) { return; } obj.CreationTime = Stopwatch.GetTimestamp(); if (obj.VoxelMaterial != null) { m_floatingOres.Add(obj); } else { m_floatingItems.Add(obj); } if (Sync.IsServer) { MyFloatingObjects.AddToSynchronization(obj); } }
private void ChangeClipboardPreview(bool visible) { if (m_copiedFloatingObjects.Count == 0 || !visible) { foreach (var grid in m_previewFloatingObjects) { MyEntities.EnableEntityBoundingBoxDraw(grid, false); grid.Close(); } m_previewFloatingObjects.Clear(); m_visible = false; return; } MyEntities.RemapObjectBuilderCollection(m_copiedFloatingObjects); foreach (var gridBuilder in m_copiedFloatingObjects) { var previewFloatingObject = MyEntities.CreateFromObjectBuilder(gridBuilder) as MyFloatingObject; if (previewFloatingObject == null) { ChangeClipboardPreview(false); return;// Not enough memory to create preview grid or there was some error. } MakeTransparent(previewFloatingObject); IsActive = visible; m_visible = visible; MyEntities.Add(previewFloatingObject); // MW: we want the floating object to be added to the scene, but we dont want to treat it as a real floating object MyFloatingObjects.UnregisterFloatingObject(previewFloatingObject); previewFloatingObject.Save = false; DisablePhysicsRecursively(previewFloatingObject); m_previewFloatingObjects.Add(previewFloatingObject); } }
public void ReleaseInventory(MyInventory inventory, bool damageContent = false) { // Spawning of floating objects and inventory modifications should be only done on the server. They are synced correctly already if (Sync.IsServer) { var items = inventory.GetItems(); foreach (var item in items) { var spawnItem = item; if (damageContent && item.Content.TypeId == typeof(MyObjectBuilder_Component)) { spawnItem.Amount *= (MyFixedPoint)MyDefinitionManager.Static.GetComponentDefinition(item.Content.GetId()).DropProbability; spawnItem.Amount = MyFixedPoint.Floor(spawnItem.Amount); if (spawnItem.Amount == 0) { continue; } } MyFloatingObjects.EnqueueInventoryItemSpawn(spawnItem, this.PositionComp.WorldAABB); } inventory.Clear(); } }
public bool DoDamage(float damage, MyStringHash damageType, bool sync, long attackerId) { if (MarkedForClose) { return(false); } if (sync) { if (Sync.IsServer) { MySyncDamage.DoDamageSynced(this, damage, damageType, attackerId); return(true); } else { return(false); } } MyDamageInformation damageinfo = new MyDamageInformation(false, damage, damageType, attackerId); if (UseDamageSystem) { MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref damageinfo); } var typeId = Item.Content.TypeId; if (typeId == typeof(MyObjectBuilder_Ore) || typeId == typeof(MyObjectBuilder_Ingot)) { if (Item.Amount < 1) { //TODO: SYNC particle MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect)) { effect.WorldMatrix = WorldMatrix; effect.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } } else { if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)damageinfo.Amount); } } } else { m_health -= 10 * damageinfo.Amount; if (UseDamageSystem) { MyDamageSystem.Static.RaiseAfterDamageApplied(this, damageinfo); } if (m_health < 0) { //TODO: SYNC particle MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect)) { effect.WorldMatrix = WorldMatrix; effect.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } //TODO: dont compare to string? if (Item.Content.SubtypeId == m_explosives && Sync.IsServer) { var expSphere = new BoundingSphere(WorldMatrix.Translation, (float)Item.Amount * 0.01f + 0.5f);// MathHelper.Clamp((float)Item.Amount, 0, 300) * 0.5f); MyExplosionInfo info = new MyExplosionInfo() { PlayerDamage = 0, Damage = 800, ExplosionType = MyExplosionTypeEnum.WARHEAD_EXPLOSION_15, ExplosionSphere = expSphere, LifespanMiliseconds = MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadeLevel = 0, HitEntity = this, ParticleScale = 1, OwnerEntity = this, Direction = WorldMatrix.Forward, VoxelExplosionCenter = expSphere.Center, ExplosionFlags = MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.APPLY_DEFORMATION, VoxelCutoutScale = 0.5f, PlaySound = true, ApplyForceAndDamage = true, ObjectsRemoveDelayInMiliseconds = 40 }; MyExplosions.AddExplosion(ref info); } if (MyFakes.ENABLE_SCRAP && Sync.IsServer) { if (Item.Content.SubtypeId == ScrapBuilder.SubtypeId) { return(true); } var contentDefinitionId = Item.Content.GetId(); if (contentDefinitionId.TypeId == typeof(MyObjectBuilder_Component)) { var definition = MyDefinitionManager.Static.GetComponentDefinition((Item.Content as MyObjectBuilder_Component).GetId()); if (MyRandom.Instance.NextFloat() < definition.DropProbability) { MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(Item.Amount * 0.8f, ScrapBuilder), PositionComp.GetPosition(), WorldMatrix.Forward, WorldMatrix.Up); } } } if (ItemDefinition != null && ItemDefinition.DestroyedPieceId.HasValue && Sync.IsServer) { MyPhysicalItemDefinition pieceDefinition; if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(ItemDefinition.DestroyedPieceId.Value, out pieceDefinition)) { MyFloatingObjects.Spawn(pieceDefinition, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, ItemDefinition.DestroyedPieces); } else { System.Diagnostics.Debug.Fail("Trying to spawn piece of the item after being destroyed, but definition wasn't found! - " + ItemDefinition.DestroyedPieceId.Value); } } if (UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(this, damageinfo); } } } return(true); }
protected override void Closing() { MyFloatingObjects.UnregisterFloatingObject(this); base.Closing(); }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); //onAddedToScene can remove floating object !! MyFloatingObjects.RegisterFloatingObject(this); }
public bool PasteFloatingObject(MyInventory buildInventory = null) { if (m_copiedFloatingObjects.Count == 0) { return(false); } if ((m_copiedFloatingObjects.Count > 0) && !IsActive) { if (CheckPastedFloatingObjects()) { Activate(); } else { MyHud.Notifications.Add(MyNotificationSingletons.CopyPasteBlockNotAvailable); MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); } return(true); } if (!m_canBePlaced) { MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); return(false); } MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceItem); MyEntities.RemapObjectBuilderCollection(m_copiedFloatingObjects); bool retVal = false; int i = 0; foreach (var floatingObjectBuilder in m_copiedFloatingObjects) { floatingObjectBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; //MyFloatingObject pastedFloatingObject = MyEntities.CreateFromObjectBuilderAndAdd(floatingObjectBuilder) as MyFloatingObject; //if (i == 0) firstPastedFloatingObject = pastedFloatingObject; //if (pastedFloatingObject == null) //{ // retVal = true; // continue; //} floatingObjectBuilder.PositionAndOrientation = new MyPositionAndOrientation(m_previewFloatingObjects[i].WorldMatrix); i++; // No velocity saving :) //floatingObjectBuilder.LinearVelocity = m_objectVelocity; //if (MySession.Static.ControlledEntity != null && MySession.Static.ControlledEntity.Entity.Physics != null && m_calculateVelocity) //{ // pastedFloatingObject.Physics.AngularVelocity = MySession.Static.ControlledEntity.Entity.Physics.AngularVelocity; //} MyFloatingObjects.RequestSpawnCreative(floatingObjectBuilder); retVal = true; } Deactivate(); return(retVal); }
public void DoDamage(float damage, MyDamageType damageType, bool sync) { if (MarkedForClose) { return; } if (sync) { if (!Sync.IsServer) { return; } else { MySyncHelper.DoDamageSynced(this, damage, damageType); return; } } var typeId = Item.Content.TypeId; if (typeId == typeof(MyObjectBuilder_Ore) || typeId == typeof(MyObjectBuilder_Ingot)) { if (Item.Amount < 1) { //TODO: SYNC particle MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect)) { effect.WorldMatrix = WorldMatrix; effect.UserScale = 0.4f; MyFloatingObjects.RemoveFloatingObject(this); } } else { if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)damage); } } } else { m_health -= (10 + 90 * DamageMultiplier) * damage; if (m_health < 0) { //TODO: SYNC particle MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect)) { effect.WorldMatrix = WorldMatrix; effect.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } //TODO: dont compare to string? if (Item.Content.SubtypeId == m_explosives && Sync.IsServer) { var expSphere = new BoundingSphere(WorldMatrix.Translation, (float)Item.Amount * 0.01f + 0.5f);// MathHelper.Clamp((float)Item.Amount, 0, 300) * 0.5f); MyExplosionInfo info = new MyExplosionInfo() { PlayerDamage = 0, Damage = 800, ExplosionType = MyExplosionTypeEnum.WARHEAD_EXPLOSION_15, ExplosionSphere = expSphere, LifespanMiliseconds = MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadeLevel = 0, HitEntity = this, ParticleScale = 1, OwnerEntity = this, Direction = WorldMatrix.Forward, VoxelExplosionCenter = expSphere.Center, ExplosionFlags = MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.APPLY_DEFORMATION, VoxelCutoutScale = 0.5f, PlaySound = true, ApplyForceAndDamage = true, ObjectsRemoveDelayInMiliseconds = 40 }; MyExplosions.AddExplosion(ref info); } if (MyFakes.ENABLE_SCRAP && Sync.IsServer) { if (Item.Content.SubtypeId == ScrapBuilder.SubtypeId) { return; } var contentDefinitionId = Item.Content.GetId(); if (contentDefinitionId.TypeId == typeof(MyObjectBuilder_Component)) { var definition = MyDefinitionManager.Static.GetComponentDefinition((Item.Content as MyObjectBuilder_Component).GetId()); if (MyRandom.Instance.NextFloat() < definition.DropProbability) { MyFloatingObjects.Spawn(new MyInventoryItem(Item.Amount * 0.8f, ScrapBuilder), PositionComp.GetPosition(), WorldMatrix.Forward, WorldMatrix.Up); } } } } } return; }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); MyFloatingObjects.RegisterFloatingObject(this); }
public bool DoDamage(float damage, MyStringHash damageType, bool sync, long attackerId) { if (base.MarkedForClose) { return(false); } if (sync) { if (!Sync.IsServer) { return(false); } MySyncDamage.DoDamageSynced(this, damage, damageType, attackerId); return(true); } MyDamageInformation information = new MyDamageInformation(false, damage, damageType, attackerId); if (this.UseDamageSystem) { MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref information); } MyObjectBuilderType typeId = this.Item.Content.TypeId; if ((typeId == typeof(MyObjectBuilder_Ore)) || (typeId == typeof(MyObjectBuilder_Ingot))) { if (this.Item.Amount >= 1) { if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)information.Amount); } } else { MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect("Smoke_Construction", base.WorldMatrix, out effect)) { effect.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } } } else { this.m_health -= 10f * information.Amount; if (this.UseDamageSystem) { MyDamageSystem.Static.RaiseAfterDamageApplied(this, information); } if (this.m_health < 0f) { MyParticleEffect effect2; MyPhysicalItemDefinition definition2; if (MyParticlesManager.TryCreateParticleEffect("Smoke_Construction", base.WorldMatrix, out effect2)) { effect2.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } if ((this.Item.Content.SubtypeId == m_explosives) && Sync.IsServer) { BoundingSphere sphere = new BoundingSphere((Vector3)base.WorldMatrix.Translation, (((float)this.Item.Amount) * 0.01f) + 0.5f); MyExplosionInfo explosionInfo = new MyExplosionInfo { PlayerDamage = 0f, Damage = 800f, ExplosionType = MyExplosionTypeEnum.WARHEAD_EXPLOSION_15, ExplosionSphere = sphere, LifespanMiliseconds = 700, HitEntity = this, ParticleScale = 1f, OwnerEntity = this, Direction = new Vector3?((Vector3)base.WorldMatrix.Forward), VoxelExplosionCenter = sphere.Center, ExplosionFlags = MyExplosionFlags.APPLY_DEFORMATION | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DEBRIS, VoxelCutoutScale = 0.5f, PlaySound = true, ApplyForceAndDamage = true, ObjectsRemoveDelayInMiliseconds = 40 }; if (this.Physics != null) { explosionInfo.Velocity = this.Physics.LinearVelocity; } MyExplosions.AddExplosion(ref explosionInfo, true); } if (MyFakes.ENABLE_SCRAP && Sync.IsServer) { if (this.Item.Content.SubtypeId == ScrapBuilder.SubtypeId) { return(true); } if (this.Item.Content.GetId().TypeId == typeof(MyObjectBuilder_Component)) { MyComponentDefinition componentDefinition = MyDefinitionManager.Static.GetComponentDefinition((this.Item.Content as MyObjectBuilder_Component).GetId()); if (MyRandom.Instance.NextFloat() < componentDefinition.DropProbability) { MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(this.Item.Amount * 0.8f, ScrapBuilder, 1f), base.PositionComp.GetPosition(), base.WorldMatrix.Forward, base.WorldMatrix.Up, null, null); } } } if (((this.ItemDefinition != null) && ((this.ItemDefinition.DestroyedPieceId != null) && Sync.IsServer)) && MyDefinitionManager.Static.TryGetPhysicalItemDefinition(this.ItemDefinition.DestroyedPieceId.Value, out definition2)) { MyFloatingObjects.Spawn(definition2, base.WorldMatrix.Translation, base.WorldMatrix.Forward, base.WorldMatrix.Up, this.ItemDefinition.DestroyedPieces, 1f); } if (this.UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(this, information); } } } return(true); }