コード例 #1
0
 public virtual void Init(MyWeaponPropertiesWrapper weaponProperties)
 {
     m_missileAmmoDefinition = weaponProperties.GetCurrentAmmoDefinitionAs <MyMissileAmmoDefinition>();
     Init(weaponProperties, m_missileAmmoDefinition.MissileModelName, false, true, true);
     m_canByAffectedByExplosionForce = false;
     UseDamageSystem = true;
 }
コード例 #2
0
        public void Init(MyObjectBuilder_GunBase objectBuilder, MyDefinitionId weaponDefinitionId, IMyGunBaseUser gunBaseUser)
        {
            m_user             = gunBaseUser;
            m_weaponProperties = new MyWeaponPropertiesWrapper(weaponDefinitionId);
            //MyDebug.AssertDebug(m_weaponProperties.AmmoMagazinesCount > 0, "Weapon definition has no ammo magazines attached.");

            // object builder area - Start
            m_remainingAmmos = new Dictionary <MyDefinitionId, int>(WeaponProperties.AmmoMagazinesCount);
            if (objectBuilder != null)
            {
                MyDefinitionId ammoMagazineDef = new MyDefinitionId(typeof(MyObjectBuilder_AmmoMagazine), objectBuilder.CurrentAmmoMagazineName);
                if (m_weaponProperties.CanChangeAmmoMagazine(ammoMagazineDef))
                {
                    CurrentAmmo = objectBuilder.RemainingAmmo;
                    m_weaponProperties.ChangeAmmoMagazine(ammoMagazineDef);
                }
                else
                {
                    if (WeaponProperties.WeaponDefinition.HasAmmoMagazines())
                    {
                        m_weaponProperties.ChangeAmmoMagazine(m_weaponProperties.WeaponDefinition.AmmoMagazinesId[0]);
                    }
                }

                foreach (var remainingAmmo in objectBuilder.RemainingAmmosList)
                {
                    m_remainingAmmos.Add(new MyDefinitionId(typeof(MyObjectBuilder_AmmoMagazine), remainingAmmo.SubtypeName), remainingAmmo.Amount);
                }

                LastShootTime = new DateTime(objectBuilder.LastShootTime);
            }
            else
            {
                if (WeaponProperties.WeaponDefinition.HasAmmoMagazines())
                {
                    m_weaponProperties.ChangeAmmoMagazine(m_weaponProperties.WeaponDefinition.AmmoMagazinesId[0]);
                }

                LastShootTime = new DateTime(0);
            }
            // object builder area - END

            if (m_user.AmmoInventory != null)
            {
                if (m_user.PutConstraint())
                {
                    MyDebug.AssertDebug(!String.IsNullOrEmpty(m_user.ConstraintDisplayName), "Display name of weapon is empty.");
                    m_user.AmmoInventory.Constraint = CreateAmmoInventoryConstraints(m_user.ConstraintDisplayName);
                }

                RefreshAmmunitionAmount();
            }

            if (m_user.Weapon != null)
            {
                m_user.Weapon.OnClosing        += Weapon_OnClosing;
                MySyncGunBase.AmmoCountChanged += MySyncGunBase_AmmoCountChanged;
            }
        }
コード例 #3
0
        static MyMissile CreateMissile(MyWeaponPropertiesWrapper weaponProperties)
        {
            MyMissile missile = new MyMissile();

            missile.Init(weaponProperties);
            m_missiles.Add(missile);
            return(missile);
        }
コード例 #4
0
ファイル: MyMissiles.cs プロジェクト: warex0/SpaceEngineers
        public static MyMissile AddUnsynced(MyWeaponPropertiesWrapper weaponProperties, Vector3D position, Vector3D initialVelocity, Vector3D direction, long ownerId)
        {
            MyMissile newMissile = CreateMissile(weaponProperties);

            newMissile.Start(position, initialVelocity, direction, ownerId);

            return(newMissile);
        }
コード例 #5
0
        //  Add new missile to the list
        public static MyMissile Add(MyWeaponPropertiesWrapper weaponProperties, Vector3D position, Vector3D initialVelocity, Vector3D direction, long ownerId)
        {
            MyMissile newMissile = AddUnsynced(weaponProperties, position, initialVelocity, direction, ownerId);

            //if (newMissile != null && Sync.IsServer)
            //{
            //    MySyncMissiles.SendMissileCreated(missileData.Launcher, position, initialVelocity, direction, missileData.CustomMaxDistance, missileData.Flags, ownerId);
            //}
            return(newMissile);
        }
コード例 #6
0
        //  Add new missile to the list
        public static MyMissile Add(MyWeaponPropertiesWrapper weaponProperties, Vector3D position, Vector3D initialVelocity, Vector3D direction, long ownerId)
        {
            MyMissile newMissile = AddUnsynced(weaponProperties, position, initialVelocity, direction, ownerId);

            // REMOVE-ME: Still commented out as of 70997. Ported to new MP events. Rmoved old sync class MySyncMissiles
            //if (newMissile != null && Sync.IsServer)
            //    MyMultiplayer.RaiseStaticEvent(s => MyMissiles.MissileCreatedSuccess, missileData.Launcher, initialVelocity);

            return(newMissile);
        }
コード例 #7
0
        private void AddProjectile(MyWeaponPropertiesWrapper weaponProperties, Vector3D initialPosition, Vector3D initialVelocity, Vector3D direction)
        {
            Vector3 projectileForwardVector = direction;

            if (weaponProperties.IsDeviated)
            {
                projectileForwardVector = GetDeviatedVector(weaponProperties.WeaponDefinition.DeviateShotAngle, direction);
            }

            MyProjectiles.Add(weaponProperties.GetCurrentAmmoDefinitionAs <MyProjectileAmmoDefinition>(), initialPosition, initialVelocity, projectileForwardVector, m_user);
        }
コード例 #8
0
        private void AddProjectile(MyWeaponPropertiesWrapper weaponProperties, Vector3D initialPosition, Vector3D initialVelocity, Vector3D direction, MyEntity owner)
        {
            Vector3 projectileForwardVector = direction;

            if (weaponProperties.IsDeviated)
            {
                projectileForwardVector = GetDeviatedVector(m_shotProjectiles + direction.GetHashCode(), weaponProperties.WeaponDefinition.DeviateShotAngle, direction);
                projectileForwardVector.Normalize();
            }

            m_shotProjectiles++;

            MyProjectiles.Add(weaponProperties.GetCurrentAmmoDefinitionAs <MyProjectileAmmoDefinition>(), initialPosition, initialVelocity, projectileForwardVector, m_user, owner);
        }
コード例 #9
0
        public static MyMissile AddUnsynced(MyWeaponPropertiesWrapper weaponProperties, Vector3D position, Vector3D initialVelocity, Vector3D direction, long ownerId)
        {
            MyMissile newMissile = CreateMissile(weaponProperties);

            if (Sync.IsServer)
            {
                //"hack" to prevent self shooting of rocket launchers if there is lag on network
                Vector3D          extendedPos = position + direction * 4.0f;
                MyPhysics.HitInfo?info        = MyPhysics.CastRay(position, extendedPos);

                //spawn rocket 4m in fron of launcher on DS (why 4 ? why not ;) ), but only if there is nothing in front of launcher
                if (info.HasValue == false)
                {
                    position = extendedPos;
                }
            }
            newMissile.Start(position, initialVelocity, direction, ownerId);

            return(newMissile);
        }
コード例 #10
0
ファイル: MyAmmoBase.cs プロジェクト: rwohleb/SpaceEngineers
        public virtual void Init(MyWeaponPropertiesWrapper weaponProperties, string modelName, bool spherePhysics = true, bool capsulePhysics = false, bool bulletType = false)
        {
            System.Diagnostics.Debug.Assert(MyEntityIdentifier.AllocationSuspended == false, "Allocation was not suspended in MyAmmoBase.Init(...)");
            bool oldSuspend = MyEntityIdentifier.AllocationSuspended;

            MyEntityIdentifier.AllocationSuspended = true;
            base.Init(null, modelName, null, null, null);

            m_weaponDefinition = weaponProperties.WeaponDefinition;

            //  Collision skin
            if (spherePhysics)
            {
                this.InitSpherePhysics(MyMaterialType.AMMO, Model, 100,
                                       MyPerGameSettings.DefaultLinearDamping,
                                       MyPerGameSettings.DefaultAngularDamping, MyPhysics.AmmoLayer,
                                       bulletType ? RigidBodyFlag.RBF_BULLET : RigidBodyFlag.RBF_DEFAULT);
            }
            if (capsulePhysics)
            {
                this.InitCapsulePhysics(MyMaterialType.AMMO, new Vector3(0, 0, -Model.BoundingBox.HalfExtents.Z * 0.8f),
                                        new Vector3(0, 0, Model.BoundingBox.HalfExtents.Z * 0.8f), 0.1f, 10, 0, 0, MyPhysics.AmmoLayer,
                                        bulletType ? RigidBodyFlag.RBF_BULLET : RigidBodyFlag.RBF_DEFAULT);
                m_ammoOffsetSize = Model.BoundingBox.HalfExtents.Z * 0.8f + 0.1f;
            }
            else
            {
                this.InitBoxPhysics(MyMaterialType.AMMO, Model, 1,
                                    MyPerGameSettings.DefaultAngularDamping, MyPhysics.AmmoLayer,
                                    bulletType ? RigidBodyFlag.RBF_BULLET : RigidBodyFlag.RBF_DEFAULT);
            }

            NeedsUpdate        = MyEntityUpdateEnum.EACH_FRAME;
            Render.CastShadows = false;
            Closed             = true; //Because ammobase instance is going to pool. It is started by Start()

            Physics.RigidBody.ContactPointCallbackEnabled = true;
            Physics.ContactPointCallback += listener_ContactPointCallback;

            MyEntityIdentifier.AllocationSuspended = oldSuspend;
        }
コード例 #11
0
        private void AddMissile(MyWeaponPropertiesWrapper weaponProperties, Vector3D initialPosition, Vector3D initialVelocity, Vector3D direction)
        {
            MyMissileAmmoDefinition missileAmmoDefinition = weaponProperties.GetCurrentAmmoDefinitionAs <MyMissileAmmoDefinition>();

            Vector3 missileDeviatedVector = direction;

            if (weaponProperties.IsDeviated)
            {
                missileDeviatedVector = GetDeviatedVector(weaponProperties.WeaponDefinition.DeviateShotAngle, direction);
                missileDeviatedVector.Normalize();
            }

            initialVelocity += missileDeviatedVector * missileAmmoDefinition.MissileInitialSpeed;

            if (m_user.Launcher != null)
            {
                MyMissiles.Add(weaponProperties, initialPosition, initialVelocity, missileDeviatedVector, m_user.OwnerId);
            }
            else
            {
                MyMissiles.AddUnsynced(weaponProperties, initialPosition + 2 * missileDeviatedVector, initialVelocity, missileDeviatedVector, m_user.OwnerId);//start missile 2 beters in front of launcher - prevents hit of own turret
            }
        }