public void Shoot(MyEntity entity, Matrix shooterMatrix, MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum weapon, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammo, MyEntity target, MyEntityIdentifier? projectileId)
        {
            if (!IsControlledByMe(entity))
            {
                return;
            }

            MyEventShoot msg = new MyEventShoot();
            msg.Position = new MyMwcPositionAndOrientation(shooterMatrix);
            msg.ShooterEntityId = entity.EntityId.Value.NumericValue;
            msg.ProjectileEntityId = MyEntityIdentifier.ToNullableInt(projectileId);
            msg.Ammo = ammo;
            msg.TargetEntityId = (target != null && target.EntityId.HasValue) ? target.EntityId.Value.NumericValue : (uint?)null;
            msg.Weapon = weapon;

            Peers.SendToAll(ref msg, NetDeliveryMethod.ReliableUnordered);
        }
        void SendCheckpoint(NetConnection sendTo)
        {
            Log("SendCheckpoint");
            var checkpointEvent = new MyEventCheckpoint();
            checkpointEvent.Checkpoint = GetCheckpoint();

            Peers.NetworkClient.Send(ref checkpointEvent, sendTo, NetDeliveryMethod.ReliableOrdered, 0, 1024 * 1024);

            // Send missiles, cannon shots etc.
            m_entitiesToTransfer.Clear();
            MyEntities.FindEntities(AmmoEntitiesPredicate, m_entitiesToTransfer);
            foreach (var e in m_entitiesToTransfer)
            {
                var ammo = (MyAmmoBase)e;

                var weapon = MyGuiSmallShipHelpers.GetFirstWeaponType(ammo.AmmoType);
                if (!weapon.HasValue) continue;

                MyEventShoot shootMsg = new MyEventShoot();
                shootMsg.Ammo = ammo.AmmoType;
                shootMsg.Position = new MyMwcPositionAndOrientation(ammo.WorldMatrix);
                shootMsg.ProjectileEntityId = MyEntityIdentifier.ToNullableInt(ammo.EntityId);
                shootMsg.ShooterEntityId = (ammo.OwnerEntity != null && ammo.OwnerEntity.EntityId.HasValue) ? ammo.OwnerEntity.EntityId.Value.NumericValue : 0;
                shootMsg.TargetEntityId = null;
                shootMsg.Weapon = weapon.Value;
                Peers.NetworkClient.Send(ref shootMsg, sendTo, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }
        void OnShoot(ref MyEventShoot msg)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Shoot");
            MyEntity parent;
            if (MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.ShooterEntityId), out parent))
            {
                if (parent is MySmallShip)
                {
                    var ship = (MySmallShip)parent;
                    ship.InitGroupMaskIfNeeded();
                    ship.WorldMatrix = msg.Position.GetMatrix();
                    if (msg.TargetEntityId.HasValue)
                    {
                        ship.TargetEntity = MyEntityIdentifier.GetEntityByIdOrNull(new MyEntityIdentifier(msg.TargetEntityId.Value));
                    }
                    var msgWeapon = msg.Weapon;
                    var weapon = GetWeapon(ship, msgWeapon);
                    if (weapon == null)
                    {
                        weapon = ship.Weapons.AddWeapon(new MyMwcObjectBuilder_SmallShip_Weapon(msg.Weapon));
                    }
                    Debug.Assert(weapon.Parent != null, "Weapon parent is null, something is wrong");
                    weapon.IsDummy = true;
                    weapon.Shot(new MyMwcObjectBuilder_SmallShip_Ammo(msg.Ammo));
                    MyEntity projectile;
                    if (msg.ProjectileEntityId.HasValue && weapon.LastShotId.HasValue && MyEntities.TryGetEntityById(weapon.LastShotId.Value, out projectile))
                    {
                        MyEntityIdentifier.RemoveEntity(weapon.LastShotId.Value);
                        projectile.EntityId = new MyEntityIdentifier(msg.ProjectileEntityId.Value);
                        if (!MyEntityIdentifier.ExistsById(projectile.EntityId.Value))
                        {
                            MyEntityIdentifier.AddEntityWithId(projectile);
                        }
                    }
                }
                else if (parent is MyPrefabLargeWeapon)
                {
                    var gun = ((MyPrefabLargeWeapon)parent).GetGun();
                    if (msg.TargetEntityId.HasValue)
                    {
                        var target = MyEntityIdentifier.GetEntityByIdOrNull(new MyEntityIdentifier(msg.TargetEntityId.Value));
                        gun.SetTarget(target);
                    }
                    
                    gun.GetBarell().IsDummy = true;
                    gun.RotateImmediately(gun.GetPosition() + msg.Position.GetMatrix().Forward * 5000);
                    gun.IsDummy = true;
                    gun.Shot(new MyMwcObjectBuilder_SmallShip_Ammo(msg.Ammo));
                    MyEntity projectile;
                    if (msg.ProjectileEntityId.HasValue && gun.LastShotId.HasValue && MyEntities.TryGetEntityById(gun.LastShotId.Value, out projectile))
                    {
                        MyEntityIdentifier.RemoveEntity(gun.LastShotId.Value);
                        projectile.EntityId = new MyEntityIdentifier(msg.ProjectileEntityId.Value);
                        if (!MyEntityIdentifier.ExistsById(projectile.EntityId.Value))
                        {
                            MyEntityIdentifier.AddEntityWithId(projectile);
                        }
                    }
                }
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }