コード例 #1
0
            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();
                    }
                }
            }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
                    }
                }
            }
        }