Exemplo n.º 1
0
        void SetAutoMountIfExceededLimit(MyMwcObjectBuilder_SmallShip_Weapon weaponObjectBuilder)
        {
            if (!weaponObjectBuilder.IsNormalWeapon)
            {
                return;
            }

            const int universalLauncherCount    = 2;
            var       maxNormalWeapons          = Ship.ShipTypeProperties.GamePlay.MaxWeapons - universalLauncherCount;
            var       maxNormalWeaponsOnOneWing = maxNormalWeapons / 2;

            var tooManyLeft  = GetNormalWeaponCount(MySlotLocationEnum.LeftSide) >= maxNormalWeaponsOnOneWing;
            var tooManyRight = GetNormalWeaponCount(MySlotLocationEnum.RightSide) >= maxNormalWeaponsOnOneWing;

            if (tooManyLeft && tooManyRight)
            {
                weaponObjectBuilder.SetAutoMount();
                return;
            }

            if (tooManyLeft)
            {
                weaponObjectBuilder.SetAutoMountRight();
            }

            if (tooManyRight)
            {
                weaponObjectBuilder.SetAutoMountLeft();
            }
        }
Exemplo n.º 2
0
        public static MyMwcObjectBuilder_SmallShip_Player CreateObjectBuilderWithAllItems(MyMwcObjectBuilder_SmallShip_TypesEnum shipType, MyMwcObjectBuilder_FactionEnum faction, int maxInventoryItems)
        {
            List <MyMwcObjectBuilder_SmallShip_Weapon> weapons        = new List <MyMwcObjectBuilder_SmallShip_Weapon>();
            List <MyMwcObjectBuilder_AssignmentOfAmmo> ammoAssignment = new List <MyMwcObjectBuilder_AssignmentOfAmmo>();
            List <MyMwcObjectBuilder_InventoryItem>    inventoryItems = new List <MyMwcObjectBuilder_InventoryItem>();

            // weapons
            foreach (MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum weapon in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum)))
            {
                var weaponBuilder = new MyMwcObjectBuilder_SmallShip_Weapon(weapon);
                weaponBuilder.SetAutoMount();
                weapons.Add(weaponBuilder);
                // we want have 2x autocanon
                if (weapon == MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Autocanon)
                {
                    var autocannonBuilder = new MyMwcObjectBuilder_SmallShip_Weapon(weapon);
                    autocannonBuilder.SetAutoMount();
                    weapons.Add(autocannonBuilder);
                }
            }

            // ammo assignment
            ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, MyMwcObjectBuilder_AmmoGroupEnum.Bullet, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic));
            ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Secondary, MyMwcObjectBuilder_AmmoGroupEnum.Missile, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic));
            ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Third, MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherFront, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Universal_Launcher_Mine_Basic));
            ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Fourth, MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherBack, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Universal_Launcher_Mine_Smart));
            ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Fifth, MyMwcObjectBuilder_AmmoGroupEnum.Bullet, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic));

            // inventory items
            // ammo
            foreach (MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammo in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum)))
            {
                inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Ammo(ammo), 1000f));
            }

            // tools
            foreach (MyMwcObjectBuilder_SmallShip_Tool_TypesEnum tool in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Tool_TypesEnum)))
            {
                inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Tool(tool), 1f));
            }

            // radars
            foreach (MyMwcObjectBuilder_SmallShip_Radar_TypesEnum radar in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Radar_TypesEnum)))
            {
                inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Radar(radar), 1f));
            }

            // engines
            foreach (MyMwcObjectBuilder_SmallShip_Engine_TypesEnum engine in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Engine_TypesEnum)))
            {
                if (engine != MyMwcObjectBuilder_SmallShip_Engine_TypesEnum.PowerCells_1)
                {
                    inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Engine(engine), 1f));
                }
            }

            // armors
            foreach (MyMwcObjectBuilder_SmallShip_Armor_TypesEnum armor in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Armor_TypesEnum)))
            {
                if (armor != MyMwcObjectBuilder_SmallShip_Armor_TypesEnum.Basic)
                {
                    inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Armor(armor), 1f));
                }
            }

            // foundation factory
            var foundationFactory = new MyMwcObjectBuilder_PrefabFoundationFactory();

            foundationFactory.PrefabHealthRatio = 1f;
            foundationFactory.PrefabMaxHealth   = null;
            inventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(foundationFactory, 1f));
            inventoryItems.RemoveAll(x => MyMwcObjectBuilder_InventoryItem.IsDisabled(x));

            if (inventoryItems.Count > maxInventoryItems)
            {
                inventoryItems = inventoryItems.GetRange(0, maxInventoryItems);
            }

            MyMwcObjectBuilder_SmallShip_Player builder =
                new MyMwcObjectBuilder_SmallShip_Player(
                    shipType,
                    new MyMwcObjectBuilder_Inventory(inventoryItems, maxInventoryItems),
                    weapons,
                    new MyMwcObjectBuilder_SmallShip_Engine(MyMwcObjectBuilder_SmallShip_Engine_TypesEnum.PowerCells_1),
                    ammoAssignment,
                    new MyMwcObjectBuilder_SmallShip_Armor(MyMwcObjectBuilder_SmallShip_Armor_TypesEnum.Basic),
                    new MyMwcObjectBuilder_SmallShip_Radar(MyMwcObjectBuilder_SmallShip_Radar_TypesEnum.Radar_1),
                    null, 1f, float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue,
                    true, false, 200f, 0);

            builder.Faction = faction;

            return(builder);
        }