Ejemplo n.º 1
0
        public void SwitchToWeapon(MyToolbarItemWeapon weapon, uint? inventoryItemId)
        {
            MyDefinitionId? weaponDefinition = null;
            if (weapon != null)
                weaponDefinition = weapon.Definition.Id;
            // CH:TODO: This part of code seems to do nothing
            if (weaponDefinition.HasValue && m_rightHandItemBone == -1)
                return;

            if (WeaponTakesBuilderFromInventory(weaponDefinition))
            {
                MyPhysicalInventoryItem? item = null;
                if (inventoryItemId.HasValue)
                {
                    item = this.GetInventory().GetItemByID(inventoryItemId.Value);
                }
                else
                {
                    item = FindWeaponItemByDefinition(weaponDefinition.Value);
                }
                // This can pop-up after inventory truncation, which is OK. Uncomment for debugging
                //Debug.Assert(item != null, "Character switched to a weapon not in the inventory");
                if (item == null)
                    return;

                Debug.Assert(item.Value.Content != null, "item.Value.Content was null in MyCharacter.SwitchToWeapon");
                if (item.Value.Content == null)
                {
                    MySandboxGame.Log.WriteLine("item.Value.Content was null in MyCharacter.SwitchToWeapon");
                    MySandboxGame.Log.WriteLine("item.Value = " + item.Value);
                    MySandboxGame.Log.WriteLine("weaponDefinition.Value = " + weaponDefinition);
                    return;
                }

                SwitchToWeaponInternal(weaponDefinition, true, item.Value.ItemId, 0);
            }
            else
            {
                SwitchToWeaponInternal(weaponDefinition, true, null, 0);
            }
        }
Ejemplo n.º 2
0
 public void SwitchToWeapon(MyToolbarItemWeapon weapon)
 {
     SwitchToWeapon(weapon, null);
 }
Ejemplo n.º 3
0
		public void SwitchToWeapon(MyToolbarItemWeapon weapon)
		{

		}
Ejemplo n.º 4
0
		public void SwitchToWeapon(MyToolbarItemWeapon weapon)
		{
			if (m_enableShipControl)
			{
				SwitchToWeaponInternal((weapon != null ? weapon.Definition.Id : (MyDefinitionId?)null), true);
			}
		}
Ejemplo n.º 5
0
        public void SwitchToWeapon(MyToolbarItemWeapon weapon, bool sync = true)
        {
            MyDefinitionId? weaponDefinition = null;
            if (weapon != null)
                weaponDefinition = weapon.Definition.Id;
            // CH:TODO: This part of code seems to do nothing
            if (weaponDefinition.HasValue && m_rightHandItemBone == -1)
                return;

            if (WeaponTakesBuilderFromInventory(weaponDefinition))
            {
                var item = FindWeaponItemByDefinition(weaponDefinition.Value);
                // This can pop-up after inventory truncation, which is OK. Uncomment for debugging
                //Debug.Assert(item != null, "Character switched to a weapon not in the inventory");
                if (item == null)
                    return;

                Debug.Assert(item.Value.Content != null, "item.Value.Content was null in MyCharacter.SwitchToWeapon");
                if (item.Value.Content == null)
                {
                    MySandboxGame.Log.WriteLine("item.Value.Content was null in MyCharacter.SwitchToWeapon");
                    MySandboxGame.Log.WriteLine("item.Value = " + item.Value);
                    MySandboxGame.Log.WriteLine("weaponDefinition.Value = " + weaponDefinition);
                    return;
                }

                var physicalGunObject = item.Value.Content as MyObjectBuilder_PhysicalGunObject;
                var gunEntity = physicalGunObject.GunEntity;
                if (gunEntity == null)
                {
                    var handItemId = MyDefinitionManager.Static.TryGetHandItemForPhysicalItem(physicalGunObject.GetId()).Id;
                    gunEntity = (MyObjectBuilder_EntityBase)MyObjectBuilderSerializer.CreateNewObject(handItemId);
                }
                else
                {
                    gunEntity.EntityId = 0;
                }

                SwitchToWeaponInternal(weaponDefinition, sync, true, gunEntity, 0);
            }
            else
            {
                SwitchToWeaponInternal(weaponDefinition, sync, true, null, 0);
            }
        }