Пример #1
0
        public static IMyInventory GetCharacterInventoryOrError(object caller, IMyCharacter character)
        {
            if (character == null)
            {
                return(null);
            }

            IMyInventory inv = character.GetInventory();

            if (inv == null)
            {
                Log.Error($"{caller?.GetType().Name} Player {character.DisplayName} has no inventory (entId={character.EntityId.ToString()})", Log.PRINT_MESSAGE);
            }

            return(inv);
        }
Пример #2
0
        /// <summary>
        ///     Check if fuel for given character is under given threshold.
        /// </summary>
        /// <param name="character">The character for which will be checked.</param>
        /// <param name="threshold">The threshold.</param>
        /// <returns>Return true if fuel is under given threshold.</returns>
        private static bool IsFuelUnderThreshold(IMyCharacter character, float threshold)
        {
            if (MyAPIGateway.Session.CreativeMode)
            {
                return(false);
            }

            var jetpackComponent = character.Components.Get <MyCharacterJetpackComponent>();
            var oxygenComponent  = character.Components.Get <MyCharacterOxygenComponent>();

            if (jetpackComponent == null || oxygenComponent == null)
            {
                return(false);
            }

            float bottleFillLevel = 0;
            var   inventory       = character.GetInventory() as MyInventory;

            if (inventory != null)
            {
                var items = inventory.GetItems();
                foreach (var item in items)
                {
                    if (item.Content.GetObjectId().ToString() == HYDROGEN_BOTTLE_ID)
                    {
                        var bottle = item.Content as MyObjectBuilder_GasContainerObject;
                        if (bottle != null)
                        {
                            bottleFillLevel += bottle.GasLevel;
                        }
                    }
                }
            }

            var hydrogenStorage        = 0.125f;
            var definition             = character.Definition as MyCharacterDefinition;
            var suitResourceDefinition = definition?.SuitResourceStorage.FirstOrDefault(x => x.Id.ToString() == HYDROGEN_ID);

            if (suitResourceDefinition != null)
            {
                hydrogenStorage = suitResourceDefinition.MaxCapacity / 1000;
            }

            return(oxygenComponent.GetGasFillLevel(MyCharacterOxygenComponent.HydrogenId) < threshold && bottleFillLevel < hydrogenStorage);
        }
Пример #3
0
    public void Remove(IMyCharacter character)
    {
        var characterInventory = character.GetInventory();

        if (characterInventory == null)
        {
            logger.WriteLine(character.Name + " has no Inventory");
            return;
        }

        MyInventory inventory = characterInventory as MyInventory;

        if (inventory == null)
        {
            logger.WriteLine(character.Name + " has no Inventory");
            return;
        }

        inventory.ClearItems();
    }
Пример #4
0
        public void Replace(IMyCharacter character)
        {
            var characterInventory = character.GetInventory();

            if (characterInventory == null)
            {
                this.messageLogger.LogMessage("Could not get character inventory");
                return;
            }

            MyInventory inventory = characterInventory as MyInventory;

            if (inventory == null)
            {
                this.messageLogger.LogMessage("Could not transform character inventory to MyInventory");
                return;
            }

            this.inventoryItemReplacer.ReplaceInventoryItem <MyObjectBuilder_PhysicalGunObject>(inventory, "AngleGrinderItem", "AngleGrinder4Item");
            this.inventoryItemReplacer.ReplaceInventoryItem <MyObjectBuilder_PhysicalGunObject>(inventory, "HandDrillItem", "HandDrill4Item");
            this.inventoryItemReplacer.ReplaceInventoryItem <MyObjectBuilder_PhysicalGunObject>(inventory, "WelderItem", "Welder4Item");
            this.inventoryItemReplacer.ReplaceInventoryItem <MyObjectBuilder_PhysicalGunObject>(inventory, "AutomaticRifleItem", "UltimateAutomaticRifleItem");
        }
Пример #5
0
        /// <summary>
        ///     Check if fuel for given character is under given threshold.
        /// </summary>
        /// <param name="character">The character for which will be checked.</param>
        /// <param name="threshold">The threshold.</param>
        /// <returns>Return true if fuel is under given threshold.</returns>
        private static bool IsFuelUnderThreshold(IMyCharacter character, float threshold)
        {
            if (MyAPIGateway.Session.CreativeMode)
            {
                return(false);
            }

            var jetpackComponent = character.Components.Get <MyCharacterJetpackComponent>();
            var oxygenComponent  = character.Components.Get <MyCharacterOxygenComponent>();

            if (jetpackComponent == null || oxygenComponent == null)
            {
                return(false);
            }

            float bottleFillLevel = 0;
            var   inventory       = character.GetInventory() as MyInventory;

            if (inventory != null)
            {
                var items = inventory.GetItems();
                foreach (var item in items)
                {
                    if (item.Content.ToString() == HYDROGEN_BOTTLE_ID)
                    {
                        var bottle = item.Content as MyObjectBuilder_GasContainerObject;
                        if (bottle != null)
                        {
                            bottleFillLevel += bottle.GasLevel;
                        }
                    }
                }
            }

            return(oxygenComponent.GetGasFillLevel(MyCharacterOxygenComponent.HydrogenId) < threshold && bottleFillLevel < 0.1);
        }
Пример #6
0
        public static int CalculatePlayerThreat(IMyCharacter character, Vector3D requesterPosition)
        {
            if (character.IsDead)
            {
                return(0);
            }
            float threat   = 0;
            float distance = (float)Vector3D.Distance(requesterPosition, character.GetPosition());

            threat += distance < 175 ? distance < 125 ? distance < 75 ? 5000 : 2500 : 1500 : 500;
            if (character.EquippedTool is IMyAngleGrinder)
            {
                threat *= 5;
            }
            IMyInventory           myInventory = character.GetInventory();
            List <MyInventoryItem> items       = new List <MyInventoryItem>();

            myInventory.GetItems(items);
            foreach (MyInventoryItem item in items)
            {
                if (item.Type == MyItemType.MakeTool("AngleGrinder4Item"))
                {
                    threat += 1000;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("AngleGrinder3Item"))
                {
                    threat += 750;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("AngleGrinder2Item"))
                {
                    threat += 500;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("AngleGrinderItem"))
                {
                    threat += 250;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("UltimateAutomaticRifleItem"))
                {
                    threat += 100;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("RapidFireAutomaticRifleItem"))
                {
                    threat += 80;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("PreciseAutomaticRifleItem"))
                {
                    threat += 60;
                    continue;
                }
                if (item.Type == MyItemType.MakeTool("AutomaticRifleItem"))
                {
                    threat += 40;
                    continue;
                }
                if (item.Type == MyItemType.MakeAmmo("NATO_5p56x45mm"))
                {
                    threat += 20;
                    continue;
                }
            }

            return((int)threat);
        }