public void OnGridsCreated(ParallelTasks.WorkData workData) { foreach (var entity in m_resultIDs) { VRage.ModAPI.IMyEntity foundEntity; MyEntityIdentifier.TryGetEntity(entity.EntityId, out foundEntity); if (foundEntity == null) { MyEntityIdentifier.AddEntityWithId(entity); } else { Debug.Fail("Two threads added the same entity"); } } foreach (var grid in m_results) { MyEntities.Add(grid); grid.IsReadyForReplication = true; } while (m_callbacks.Count > 0) { var callback = m_callbacks.Pop(); if (callback != null) { callback(); } } }
public void OnAmmoUpdate(ref MyEventAmmoUpdate msg) { var player = (MyPlayerRemote)msg.SenderConnection.Tag; if (player != null) { MyEntity projectile; if (MyEntityIdentifier.TryGetEntity(new MyEntityIdentifier(msg.EntityId), out projectile)) { projectile.WorldMatrix = msg.Position.GetMatrix(); projectile.Physics.LinearVelocity = msg.Velocity; } } }
public static bool TryGetCubeGridById(long gridId, out MyCubeGrid grid) { if (!MyEntityIdentifier.TryGetEntity(gridId, out var entity)) { grid = null; return(false); } if (!(entity is MyCubeGrid g)) { throw new Exception($"Not a grid: {gridId} -> {entity.GetType()}"); } grid = g; return(true); }
public void OnSpecialWeaponEvent(ref MyEventSpeacialWeapon msg) { var player = (MyPlayerRemote)msg.SenderConnection.Tag; if (player != null) { MyEntity entity; if (MyEntityIdentifier.TryGetEntity(new MyEntityIdentifier(msg.ShipEntityId), out entity) && entity is MySmallShip) { MySmallShip ship = (MySmallShip)entity; switch (msg.WeaponEvent) { case MySpecialWeaponEventEnum.HARVESTER_FIRE: OnFireHarvester(msg.Weapon, ship); break; case MySpecialWeaponEventEnum.DRILL_ACTIVATED: EnsureDrill(msg.Weapon, ship).CurrentState = MyDrillStateEnum.Activated; break; case MySpecialWeaponEventEnum.DRILL_DEACTIVATED: EnsureDrill(msg.Weapon, ship).CurrentState = MyDrillStateEnum.Deactivated; break; case MySpecialWeaponEventEnum.DRILL_DRILLING: { var drill = EnsureDrill(msg.Weapon, ship); drill.Shot(null); drill.CurrentState = MyDrillStateEnum.Drilling; } break; default: break; } } } }