Exemplo n.º 1
0
        private static void UnpackMothership()
        {
            MyTrace.Send(TraceWindow.Saving, "Player unpacking mothership");
            MyInventoryItem item = MySession.Static.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.PrefabContainer, null);

            if (item != null)
            {
                //place largeship
                //MyMwcObjectBuilder_LargeShip largeShipObjectBuilder = (MyMwcObjectBuilder_LargeShip)inventoryItems[0].GetObjectBuilder(true);
                MyMwcObjectBuilder_PrefabContainer containerObjectBuilder =
                    (MyMwcObjectBuilder_PrefabContainer)item.GetInventoryItemObjectBuilder(true);

                // We need to remove id's because mothership container could have same entity id in different sector
                containerObjectBuilder.RemapEntityIds(new MyEntityIdRemapContext());

                MyPrefabContainer container = new MyPrefabContainer();
                container.Init(null, containerObjectBuilder, FindMothershipPosition());

                MyEntities.Add(container);

                //CreateFromObjectBuilderAndAdd(null, largeShipObjectBuilder, Matrix.CreateTranslation(MySession.PlayerShip.GetPosition() + new Vector3(100,100,0)));
                MySession.Static.Inventory.RemoveInventoryItem(item);

                container.Link();

                MyTrace.Send(TraceWindow.Saving, "Player mothership found and unpacked");
            }
        }
        private MyGuiControlListboxItem CreateCopy(MyGuiControlListboxItem original)
        {
            MyInventoryItem templateInventoryItem = m_inventoryItemsRepository.GetItem(original.Key);
            MyInventoryItem newInventoryItem      = MyInventory.CreateInventoryItemFromObjectBuilder(templateInventoryItem.GetInventoryItemObjectBuilder(true));

            newInventoryItem.Amount = templateInventoryItem.Amount;
            MyGuiControlListboxItem newItem = CreateListboxItemAndAddToRepository(newInventoryItem);

            newItem.IconTexts = original.IconTexts;
            m_itemsAdded.Add(newInventoryItem);
            return(newItem);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Shot from weapon which is bind at fire key
        /// </summary>
        /// <param name="key">Fire key</param>
        void FirePrivate(MyMwcObjectBuilder_FireKeyEnum key)
        {
            //Do nothing if there are no ammo or weapons or assignments


            this.m_ship.InitGroupMaskIfNeeded();

            var drill = GetMountedDrill();

            if ((!MySession.Is25DSector && (drill != null && (drill.CurrentState == MyDrillStateEnum.Activated || drill.CurrentState == MyDrillStateEnum.Drilling))) ||
                (MySession.Is25DSector && drill != null && key == MyMwcObjectBuilder_FireKeyEnum.Secondary))
            {
                drill.Shot(null);
                return;
            }

            List <MySmallShipGunBase> mountedGuns = GetMountedWeaponsWithHarvesterAndDrill();

            /*if (AmmoInventoryItems.Count() == 0 || AmmoAssignments.Count() == 0 || mountedGuns.Count == 0)
             *  return;*/

            MyAmmoAssignment ammoAssignment = AmmoAssignments.GetAmmoAssignment(key);

            //If type or group is not found in object builders, do nothing
            if (ammoAssignment == null)
            {
                return;
            }

            //If type and group is bad combination, do nothing
            if (!MyGuiSmallShipHelpers.GetWeaponType(ammoAssignment.AmmoType, ammoAssignment.AmmoGroup).HasValue)
            {
                return;
            }

            MyInventoryItem usedAmmoInventoryItem = null;

            foreach (MyInventoryItem ammoItem in AmmoInventoryItems.GetAmmoInventoryItems(ammoAssignment.AmmoType))
            {
                if (ammoItem.Amount > 0)
                {
                    usedAmmoInventoryItem = ammoItem;
                    break;
                }
            }

            bool thereWasShot         = false;
            bool wasCountedMuzzleTime = false;

            //  Shot from gun
            foreach (MySmallShipGunBase gun in mountedGuns)
            {
                if (MyGuiSmallShipHelpers.GetWeaponType(ammoAssignment.AmmoType, ammoAssignment.AmmoGroup).Value == gun.WeaponType)
                {
                    bool shot = false;
                    if (usedAmmoInventoryItem != null && usedAmmoInventoryItem.Amount > 0)
                    {
                        shot = gun.Shot((MyMwcObjectBuilder_SmallShip_Ammo)usedAmmoInventoryItem.GetInventoryItemObjectBuilder(false));
                        if (shot && MyMultiplayerGameplay.IsRunning && !m_ship.IsDummy)
                        {
                            var ammo = ((MyMwcObjectBuilder_SmallShip_Ammo)usedAmmoInventoryItem.GetInventoryItemObjectBuilder(false)).AmmoType;
                            MyMultiplayerGameplay.Static.Shoot(this.m_ship, this.m_ship.WorldMatrix, gun.WeaponType, ammo, this.Ship.TargetEntity, gun.LastShotId);
                        }
                    }
                    else
                    {
                        if (m_noAmmoSoundDelay + 175 < MyMinerGame.TotalGamePlayTimeInMilliseconds)
                        {
                            Audio.MyAudio.AddCue2dOr3d(Ship, Audio.MySoundCuesEnum.WepNoAmmo, Ship.GetPosition(), Ship.WorldMatrix.Forward, Ship.WorldMatrix.Up, Ship.Physics.LinearVelocity);
                            m_noAmmoSoundDelay = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        }
                    }

                    if (shot)
                    {
                        Ship.Inventory.RemoveInventoryItemAmount(ref usedAmmoInventoryItem, 1f);
                        thereWasShot = true;
                        Ship.WeaponShot(gun, ammoAssignment);
                    }

                    //  If we shot from gun that uses projectiles, we need to remember it as last time of muzzle flash
                    if ((shot == true) &&
                        MyGuiSmallShipHelpers.IsAmmoInGroup(ammoAssignment.AmmoType, MyMwcObjectBuilder_AmmoGroupEnum.Bullet) &&
                        !wasCountedMuzzleTime)
                    {
                        MuzzleFlashLastTime  = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        wasCountedMuzzleTime = true;
                    }
                }
            }

            if (thereWasShot == true)
            {
                Ship.IncreaseHeadShake(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_AFTER_GUN_SHOT);
            }
        }