コード例 #1
0
        public static void SendToClients(RailgunFireData data)
        {
            //Below, save your data to string or some other serializable type
            var sendData = MyAPIGateway.Utilities.SerializeToBinary(data);

            //Send the message to the ID you registered in Setup, and specify the user via SteamId
            bool sendStatus = MyAPIGateway.Multiplayer.SendMessageToOthers(NetID, sendData);
        }
コード例 #2
0
        public static void ShootProjectileServer(RailgunFireData fireData)
        {
            RailgunProjectileData projectileData;
            bool registered = railgunDataDict.TryGetValue(fireData.ShooterID, out projectileData);

            if (!registered)
            {
                return;
            }

            var projectile = new ArmorPiercingProjectile(fireData, projectileData);

            AddProjectile(projectile);
        }
コード例 #3
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();
            try
            {
                if (cube?.CubeGrid?.Physics == null) //ignore ghost grids
                {
                    return;
                }

                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    Vector3D direction;
                    Vector3D origin;

                    _currentShootTime = GetLastShootTime();

                    //fire weapon
                    if (_currentShootTime != _lastShootTime && !_firstUpdate)
                    {
                        if (Entity is IMyLargeTurretBase)
                        {
                            Vector3D.CreateFromAzimuthAndElevation(turret.Azimuth, turret.Elevation, out direction);
                            direction = Vector3D.TransformNormal(direction, turret.WorldMatrix);
                            origin    = turret.WorldMatrix.Translation + turret.WorldMatrix.Up * 1.75 + direction * 0.5;
                        }
                        else
                        {
                            direction = block.WorldMatrix.Forward;
                            origin    = block.WorldMatrix.Translation + direction * -2.5; //for cushion
                        }

                        var velocity = block.CubeGrid.Physics.LinearVelocity;
                        //var projectile = new ArmorPiercingProjectileSimulation(origin, direction, velocity, this._desiredSpeed, this._maxTrajectory, 0f, 0f, _projectileDamage, 50f, Entity.EntityId, _trailColor, _trailScale, true, true, true);
                        var fireData = new RailgunFireData()
                        {
                            ShooterVelocity = velocity,
                            Origin          = origin,
                            Direction       = direction,
                            ShooterID       = Entity.EntityId
                        };

                        RailgunCore.ShootProjectileServer(fireData);
                        //RailgunCore.AddProjectile(projectile);

                        _isReloading        = true;
                        _currentReloadTicks = 0;

                        //Apply recoil force
                        var centerOfMass = block.CubeGrid.Physics.CenterOfMassWorld;
                        var forceVector  = -direction * _backkickForce;

                        block.CubeGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, forceVector, block.GetPosition(), null);

                        //MyAPIGateway.Utilities.ShowNotification("Shot", 3000);
                    }

                    _lastShootTime = _currentShootTime;
                    sink.Update();
                    _firstUpdate = false;
                }

                ShowReloadMessage();

                //MyAPIGateway.Utilities.ShowNotification($"Power draw: {GetPowerInput(false):n0} MW | reloading?: {_isReloading} | max: {sink.MaxRequiredInputByType(resourceId)} | current ticks {_currentReloadTicks}", 16, MyFontEnum.Blue);
            }
            catch (Exception e)
            {
                MyAPIGateway.Utilities.ShowNotification("Exception in update", 16, MyFontEnum.Red);
                MyLog.Default.WriteLine(e);
            }
        }
コード例 #4
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();
            try
            {
                if (cube?.CubeGrid?.Physics == null) //ignore ghost grids
                {
                    return;
                }

                _currentShootTime = GetLastShootTime();

                if (_currentShootTime != _lastShootTime && !_firstUpdate)
                {
                    _isReloading = true;

                    //fire weapon
                    if (MyAPIGateway.Multiplayer.IsServer)
                    {
                        Vector3D direction;
                        Vector3D origin;

                        if (Entity is IMyLargeTurretBase)
                        {
                            Vector3D.CreateFromAzimuthAndElevation(turret.Azimuth, turret.Elevation, out direction);
                            direction = Vector3D.TransformNormal(direction, turret.WorldMatrix);
                            origin    = turret.WorldMatrix.Translation + turret.WorldMatrix.Up * 1.75 + direction * 0.5;
                        }
                        else
                        {
                            direction = block.WorldMatrix.Forward;
                            origin    = block.WorldMatrix.Translation + direction * -2.5; //for cushion
                        }

                        var velocity = block.CubeGrid.Physics.LinearVelocity;

                        var fireData = new RailgunFireData()
                        {
                            ShooterVelocity = velocity,
                            Origin          = origin,
                            Direction       = direction,
                            ShooterID       = Entity.EntityId,
                        };

                        RailgunCore.ShootProjectileServer(fireData);

                        _currentReloadTicks = 0;

                        //Apply recoil force
                        var centerOfMass = block.CubeGrid.Physics.CenterOfMassWorld;
                        var forceVector  = -direction * _backkickForce;

                        block.CubeGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, forceVector, block.GetPosition(), null);
                    }
                }

                _lastShootTime = _currentShootTime;
                _firstUpdate   = false;
                ShowReloadMessage();
            }
            catch (Exception e)
            {
                MyAPIGateway.Utilities.ShowNotification("Exception in update", 16, MyFontEnum.Red);
                MyLog.Default.WriteLine(e);
            }
        }