Exemple #1
0
        public override void AddItems(MyCharacter character)
        {
            MyWeaponDefinition definition;

            base.AddItems(character);
            MyObjectBuilder_PhysicalGunObject objectBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(this.StartingWeaponDefinitionId.SubtypeName);

            if (character.WeaponTakesBuilderFromInventory(new MyDefinitionId?(this.StartingWeaponDefinitionId)))
            {
                character.GetInventory(0).AddItems(1, objectBuilder);
            }
            foreach (MyDefinitionId id in this.InventoryItems)
            {
                objectBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(id.SubtypeName);
                character.GetInventory(0).AddItems(1, objectBuilder);
            }
            character.SwitchToWeapon(this.StartingWeaponDefinitionId);
            MyDefinitionId defId = new MyDefinitionId(typeof(MyObjectBuilder_WeaponDefinition), this.StartingWeaponDefinitionId.SubtypeName);

            if (MyDefinitionManager.Static.TryGetWeaponDefinition(defId, out definition) && definition.HasAmmoMagazines())
            {
                MyObjectBuilder_AmmoMagazine magazine = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_AmmoMagazine>(definition.AmmoMagazinesId[0].SubtypeName);
                character.GetInventory(0).AddItems(3, magazine);
            }
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            MyObjectBuilder_AutomaticRifle rifleBuilder = (MyObjectBuilder_AutomaticRifle)objectBuilder;

            m_handItemDefId = rifleBuilder.GetId();
            if (string.IsNullOrEmpty(m_handItemDefId.SubtypeName))
            {
                m_handItemDefId = new MyDefinitionId(typeof(MyObjectBuilder_AutomaticRifle), "RifleGun");
            }

            var handItemDef = MyDefinitionManager.Static.TryGetHandItemDefinition(ref m_handItemDefId);

            m_physicalItemDef = MyDefinitionManager.Static.GetPhysicalItemForHandItem(m_handItemDefId);

            MyDefinitionId weaponDefinitionId;

            if (m_physicalItemDef is MyWeaponItemDefinition)
            {
                weaponDefinitionId = (m_physicalItemDef as MyWeaponItemDefinition).WeaponDefinitionId;
            }
            else
            {
                weaponDefinitionId = new MyDefinitionId(typeof(MyObjectBuilder_WeaponDefinition), "AutomaticRifleGun");
            }

            // muzzle location
            m_gunBase.Init(rifleBuilder.GunBase, weaponDefinitionId, this);

            base.Init(objectBuilder);

            Init(new StringBuilder("Rifle"), m_physicalItemDef.Model, null, null, null);

            var model = VRage.Game.Models.MyModels.GetModelOnlyDummies(m_physicalItemDef.Model);

            m_gunBase.LoadDummies(model.Dummies);

            // backward compatibility for models without dummies or old dummies
            if (!m_gunBase.HasDummies)
            {
                Matrix muzzleMatrix = Matrix.CreateTranslation(handItemDef.MuzzlePosition);
                m_gunBase.AddMuzzleMatrix(MyAmmoType.HighSpeed, muzzleMatrix);
            }

            PhysicalObject                    = (MyObjectBuilder_PhysicalGunObject)MyObjectBuilderSerializer.CreateNewObject(m_physicalItemDef.Id.TypeId, m_physicalItemDef.Id.SubtypeName);
            PhysicalObject.GunEntity          = (MyObjectBuilder_EntityBase)rifleBuilder.Clone();
            PhysicalObject.GunEntity.EntityId = this.EntityId;
            CurrentAmmunition                 = rifleBuilder.CurrentAmmo;
        }
Exemple #3
0
        protected MyBehaviorTreeState EquipItem([BTParam] string itemName)
        {
            if (string.IsNullOrEmpty(itemName))
            {
                return(MyBehaviorTreeState.FAILURE);
            }
            MyCharacter humanoidEntity = this.Bot.HumanoidEntity;

            if ((humanoidEntity.CurrentWeapon == null) || (humanoidEntity.CurrentWeapon.DefinitionId.SubtypeName != itemName))
            {
                MyObjectBuilder_PhysicalGunObject self = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(itemName);
                MyDefinitionId id = self.GetId();
                if (!humanoidEntity.GetInventory(0).ContainItems(1, self) && humanoidEntity.WeaponTakesBuilderFromInventory(new MyDefinitionId?(id)))
                {
                    return(MyBehaviorTreeState.FAILURE);
                }
                humanoidEntity.SwitchToWeapon(id);
            }
            return(MyBehaviorTreeState.SUCCESS);
        }