コード例 #1
0
        public void Adapt(IMyInventoryItem inventoryItem)
        {
            m_physItem = null;
            m_blockDef = null;

            var poob = inventoryItem.Content as MyObjectBuilder_PhysicalObject;
            if (poob != null) Adapt(poob.GetObjectId());
            else Adapt(inventoryItem.GetDefinitionId());
        }
コード例 #2
0
        public bool TryAdapt(MyDefinitionId itemDefinition)
        {
            m_physItem = null;
            m_blockDef = null;

            if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(itemDefinition, out m_physItem)) return true;
            if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(itemDefinition, out m_blockDef)) return true;

            return false;
        }
コード例 #3
0
            public FuelInfo(MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo fuelInfo, MyReactorDefinition blockDefinition)
            {
                this.FuelId         = fuelInfo.Id;
                this.Ratio          = fuelInfo.Ratio;
                this.FuelDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(fuelInfo.Id);
                this.FuelItem       = MyObjectBuilderSerializer.CreateNewObject(fuelInfo.Id) as MyObjectBuilder_PhysicalObject;
                float num = (blockDefinition.MaxPowerOutput / blockDefinition.FuelProductionToCapacityMultiplier) * this.Ratio;

                this.ConsumptionPerSecond_Items = num / this.FuelDefinition.Mass;
            }
コード例 #4
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            m_definition = MyDefinitionManager.Static.GetPhysicalItemDefinition(objectBuilder.GetId());

            Init(null, m_definition.Model, null, null, null);

            Render.SkipIfTooSmall = false;
            Render.NeedsDraw = true;

            this.InitSpherePhysics(MyMaterialType.METAL, Model, 1, 1, 1, 0, RigidBodyFlag.RBF_DEFAULT);

            Physics.Enabled = true;
        }
コード例 #5
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var generatorBuilder = builder as MyObjectBuilder_ReactorDefinition;
            MyDebug.AssertDebug(generatorBuilder != null, "Initializing thrust definition using wrong object builder.");
            InventorySize = generatorBuilder.InventorySize;
            InventoryMaxVolume = InventorySize.X * InventorySize.Y * InventorySize.Z;

            FuelId = generatorBuilder.FuelId;
            FuelDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(FuelId);
            MyDebug.AssertDebug(FuelDefinition != null);

            FuelItem = MyObjectBuilderSerializer.CreateNewObject(generatorBuilder.FuelId) as MyObjectBuilder_PhysicalObject;
            MyDebug.AssertDebug(FuelItem != null);

            //StringBuilder constraintTooltip = new StringBuilder();
            //constraintTooltip.Append(FuelDefinition.DisplayNameText);
            //InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId);
            String constraintTooltip = FuelDefinition.DisplayNameText;
            InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId);
        }
コード例 #6
0
        public CommandInventoryDrop(string[] oreNames, string[] ingotNames, MyPhysicalItemDefinition[] physicalItems)
            : base(ChatCommandSecurity.Admin, "drop", new[] { "/drop" })
        {
            _oreNames = oreNames;
            _ingotNames = ingotNames;
            _physicalItems = physicalItems;

            // Make sure all Public Physical item names are unique, so they can be properly searched for.
            var names = new List<string>();
            foreach (var item in _physicalItems)
            {
                var baseName = item.DisplayNameEnum.HasValue ? item.DisplayNameEnum.Value.GetString() : item.DisplayNameString;
                var uniqueName = baseName;
                var index = 1;
                while (names.Contains(uniqueName, StringComparer.InvariantCultureIgnoreCase))
                {
                    index++;
                    uniqueName = string.Format("{0}{1}", baseName, index);
                }
                names.Add(uniqueName);
            }
            _physicalItemNames = names.ToArray();
        }
コード例 #7
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var generatorBuilder = builder as MyObjectBuilder_ReactorDefinition;

            MyDebug.AssertDebug(generatorBuilder != null, "Initializing thrust definition using wrong object builder.");
            InventorySize      = generatorBuilder.InventorySize;
            InventoryMaxVolume = InventorySize.X * InventorySize.Y * InventorySize.Z;

            FuelId         = generatorBuilder.FuelId;
            FuelDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(FuelId);
            MyDebug.AssertDebug(FuelDefinition != null);

            FuelItem = MyObjectBuilderSerializer.CreateNewObject(generatorBuilder.FuelId) as MyObjectBuilder_PhysicalObject;
            MyDebug.AssertDebug(FuelItem != null);

            //StringBuilder constraintTooltip = new StringBuilder();
            //constraintTooltip.Append(FuelDefinition.DisplayNameText);
            //InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId);
            String constraintTooltip = FuelDefinition.DisplayNameText;

            InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId);
        }
コード例 #8
0
            internal ItemIconControl(MyPhysicalItemDefinition def)
                : base( size: MyGuiConstants.TEXTURE_GRID_ITEM.SizeGui * SCALE,
                        backgroundTexture: new MyGuiCompositeTexture(MyGuiConstants.TEXTURE_GRID_ITEM.Normal),
                        isActiveControl: false)
            {
                MinSize = MaxSize = Size;
                var padding = new MyGuiBorderThickness(0.0025f, 0.001f);

                for (int i = 0; i < def.Icons.Length; i++)
                    Elements.Add(new MyGuiControlPanel(
                        size: Size - padding.SizeChange,
                        texture: def.Icons[0]));

                if (def.IconSymbol.HasValue)
                {
                    Elements.Add(new MyGuiControlLabel(
                        position: -0.5f * Size + padding.TopLeftOffset,
                        text: MyTexts.GetString(def.IconSymbol.Value),
                        textScale: SCALE,
                        originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP));
                }
            }
コード例 #9
0
        /// <summary>
        /// Find the physical object of the specified name or partial name.
        /// </summary>
        /// <param name="itemName">The name of the physical object to find.</param>
        /// <param name="objectBuilder">The object builder of the physical object, ready for use.</param>
        /// <param name="options">Returns a list of potential matches if there was more than one of the same or partial name.</param>
        /// <returns>Returns true if a single exact match was found.</returns>
        public static bool FindPhysicalParts(string[] _oreNames, string[] _ingotNames, string[] _physicalItemNames, MyPhysicalItemDefinition[] _physicalItems, string itemName, out MyObjectBuilder_Base objectBuilder, out string[] options)
        {
            var itemNames = itemName.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // prefix the search term with 'ore' to find this ore name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ore", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(4).Trim();

                var exactMatchOres = _oreNames.Where(ore => ore.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToArray();
                if (exactMatchOres.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = exactMatchOres[0] };
                    options = new string[0];
                    return true;
                }
                else if (exactMatchOres.Length > 1)
                {
                    objectBuilder = null;
                    options = exactMatchOres;
                    return false;
                }

                var partialMatchOres = _oreNames.Where(ore => ore.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray();
                if (partialMatchOres.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ore() { SubtypeName = partialMatchOres[0] };
                    options = new string[0];
                    return true;
                }
                else if (partialMatchOres.Length > 1)
                {
                    objectBuilder = null;
                    options = partialMatchOres;
                    return false;
                }

                objectBuilder = null;
                options = new string[0];
                return false;
            }

            // prefix the search term with 'ingot' to find this ingot name.
            if (itemNames.Length > 1 && itemNames[0].Equals("ingot", StringComparison.InvariantCultureIgnoreCase))
            {
                var findName = itemName.Substring(6).Trim();

                var exactMatchIngots = _ingotNames.Where(ingot => ingot.Equals(findName, StringComparison.InvariantCultureIgnoreCase)).ToArray();
                if (exactMatchIngots.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = exactMatchIngots[0] };
                    options = new string[0];
                    return true;
                }
                else if (exactMatchIngots.Length > 1)
                {
                    objectBuilder = null;
                    options = exactMatchIngots;
                    return false;
                }

                var partialMatchIngots = _ingotNames.Where(ingot => ingot.IndexOf(findName, StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray();
                if (partialMatchIngots.Length == 1)
                {
                    objectBuilder = new MyObjectBuilder_Ingot() { SubtypeName = partialMatchIngots[0] };
                    options = new string[0];
                    return true;
                }
                else if (partialMatchIngots.Length > 1)
                {
                    objectBuilder = null;
                    options = partialMatchIngots;
                    return false;
                }

                objectBuilder = null;
                options = new string[0];
                return false;
            }

            // full name match.
            var res = _physicalItemNames.FirstOrDefault(s => s != null && s.Equals(itemName, StringComparison.InvariantCultureIgnoreCase));

            // need a good method for finding partial name matches.
            if (res == null)
            {
                var matches = _physicalItemNames.Where(s => s != null && s.StartsWith(itemName, StringComparison.InvariantCultureIgnoreCase)).Distinct().ToArray();

                if (matches.Length == 1)
                {
                    res = matches.FirstOrDefault();
                }
                else
                {
                    matches = _physicalItemNames.Where(s => s != null && s.IndexOf(itemName, StringComparison.InvariantCultureIgnoreCase) >= 0).Distinct().ToArray();
                    if (matches.Length == 1)
                    {
                        res = matches.FirstOrDefault();
                    }
                    else if (matches.Length > 1)
                    {
                        objectBuilder = null;
                        options = matches;
                        return false;
                    }
                }
            }

            if (res != null)
            {
                var item = _physicalItems[Array.IndexOf(_physicalItemNames, res)];
                if (item != null)
                {
                    objectBuilder = MyObjectBuilderSerializer.CreateNewObject(item.Id.TypeId, item.Id.SubtypeName);
                    options = new string[0];
                    return true;
                }
            }

            objectBuilder = null;
            options = new string[0];
            return false;
        }
コード例 #10
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_CubeBlockDefinition;

            MyDebug.AssertDebug(ob != null);

            this.Size  = ob.Size;
            this.Model = ob.Model;
            this.UseModelIntersection = ob.UseModelIntersection;
            this.CubeSize             = ob.CubeSize;
            this.ModelOffset          = ob.ModelOffset;
            this.BlockTopology        = ob.BlockTopology;
            this.PhysicsOption        = ob.PhysicsOption;
            this.BlockPairName        = ob.BlockPairName;
            this.m_center             = ob.Center ?? ((Size - 1) / 2);
            this.m_symmetryX          = ob.MirroringX;
            this.m_symmetryY          = ob.MirroringY;
            this.m_symmetryZ          = ob.MirroringZ;
            this.DeformationRatio     = ob.DeformationRatio;
            this.EdgeType             = ob.EdgeType;
            this.AutorotateMode       = ob.AutorotateMode;
            this.m_mirroringBlock     = ob.MirroringBlock;
            this.MultiBlock           = ob.MultiBlock;
            this.GuiVisible           = ob.GuiVisible;
            this.Rotation             = ob.Rotation;
            this.Direction            = ob.Direction;
            this.Mirrored             = ob.Mirrored;
            this.RandomRotation       = ob.RandomRotation;
            this.BuildType            = MyStringId.GetOrCompute(ob.BuildType != null ? ob.BuildType.ToLower() : null);
            this.BuildMaterial        = ob.BuildMaterial != null?ob.BuildMaterial.ToLower() : null;

            this.BuildProgressToPlaceGeneratedBlocks = ob.BuildProgressToPlaceGeneratedBlocks;
            this.GeneratedBlockType    = MyStringId.GetOrCompute(ob.GeneratedBlockType != null ? ob.GeneratedBlockType.ToLower() : null);
            this.CompoundEnabled       = ob.CompoundEnabled;
            this.CreateFracturedPieces = ob.CreateFracturedPieces;
            if (ob.PhysicalMaterial != null)
            {
                this.PhysicalMaterial = MyDefinitionManager.Static.GetPhysicalMaterialDefinition(ob.PhysicalMaterial);
            }
            if (ob.DamageEffectId != 0)
            {
                this.DamageEffectID = ob.DamageEffectId;
            }

            this.Points = ob.Points;
            InitEntityComponents(ob.EntityComponents);

            this.CompoundTemplates = ob.CompoundTemplates;
            Debug.Assert(this.CompoundTemplates == null || this.CompoundTemplates.Length > 0, "Wrong compound templates, array is empty");

            if (ob.SubBlockDefinitions != null)
            {
                SubBlockDefinitions = new Dictionary <string, MyDefinitionId>();

                foreach (var definition in ob.SubBlockDefinitions)
                {
                    MyDefinitionId defId;
                    if (SubBlockDefinitions.TryGetValue(definition.SubBlock, out defId))
                    {
                        MyDebug.AssertDebug(false, "Subblock definition already defined!");
                        continue;
                    }

                    defId = definition.Id;
                    SubBlockDefinitions.Add(definition.SubBlock, defId);
                }
            }

            if (ob.BlockVariants != null)
            {
                BlockStages = new MyDefinitionId[ob.BlockVariants.Length];

                for (int i = 0; i < ob.BlockVariants.Length; ++i)
                {
                    BlockStages[i] = ob.BlockVariants[i];
                }
            }

            var cubeDef = ob.CubeDefinition;

            if (cubeDef != null)
            {
                MyCubeDefinition tmp = new MyCubeDefinition();
                tmp.CubeTopology = cubeDef.CubeTopology;
                tmp.ShowEdges    = cubeDef.ShowEdges;

                var sides = cubeDef.Sides;
                tmp.Model       = new string[sides.Length];
                tmp.PatternSize = new Vector2I[sides.Length];
                for (int j = 0; j < sides.Length; ++j)
                {
                    var side = sides[j];
                    tmp.Model[j]       = side.Model;
                    tmp.PatternSize[j] = side.PatternSize;
                }
                this.CubeDefinition = tmp;
            }

            var components = ob.Components;

            MyDebug.AssertDebug(components != null);
            MyDebug.AssertDebug(components.Length != 0);
            float mass = 0.0f;
            float criticalIntegrity  = 0f;
            float ownershipIntegrity = 0f;

            if (components != null && components.Length != 0)
            {
                Components = new MyCubeBlockDefinition.Component[components.Length];

                float integrity           = 0.0f;
                int   criticalTypeCounter = 0;
                for (int j = 0; j < components.Length; ++j)
                {
                    var component = components[j];

                    var definition = MyDefinitionManager.Static.GetComponentDefinition(new MyDefinitionId(component.Type, component.Subtype));
                    MyPhysicalItemDefinition deconstructDefinition = null;
                    if (!component.DeconstructId.IsNull() && !MyDefinitionManager.Static.TryGetPhysicalItemDefinition(component.DeconstructId, out deconstructDefinition))
                    {
                        deconstructDefinition = definition;
                    }

                    if (deconstructDefinition == null)
                    {
                        deconstructDefinition = definition;
                    }

                    MyCubeBlockDefinition.Component tmp = new MyCubeBlockDefinition.Component()
                    {
                        Definition      = definition,
                        Count           = component.Count,
                        DeconstructItem = deconstructDefinition,
                    };

                    if (component.Type == typeof(MyObjectBuilder_Component) && component.Subtype == "Computer")
                    {
                        if (ownershipIntegrity == 0)
                        {
                            ownershipIntegrity = integrity + tmp.Definition.MaxIntegrity;
                        }
                    }

                    integrity += tmp.Count * tmp.Definition.MaxIntegrity;
                    if (component.Type == ob.CriticalComponent.Type &&
                        component.Subtype == ob.CriticalComponent.Subtype)
                    {
                        if (criticalTypeCounter == ob.CriticalComponent.Index)
                        {
                            CriticalGroup     = (UInt16)j;
                            criticalIntegrity = integrity - 1;
                        }
                        ++criticalTypeCounter;
                    }

                    mass += tmp.Count * tmp.Definition.Mass;

                    Components[j] = tmp;
                }

                MaxIntegrity = integrity;

                if (ob.MaxIntegrity != 0)
                {
                    criticalIntegrity = ob.MaxIntegrity * criticalIntegrity / MaxIntegrity;
                    MaxIntegrity      = ob.MaxIntegrity;
                }

                IntegrityPointsPerSec = MaxIntegrity / ob.BuildTimeSeconds;
                DisassembleRatio      = ob.DisassembleRatio;
                if (!MyPerGameSettings.Destruction)
                {
                    Mass = mass;
                }
            }
            else
            {
                if (ob.MaxIntegrity != 0)
                {
                    MaxIntegrity = ob.MaxIntegrity;
                }
            }

            CriticalIntegrityRatio  = criticalIntegrity / MaxIntegrity;
            OwnershipIntegrityRatio = ownershipIntegrity / MaxIntegrity;

            if (ob.BuildProgressModels != null)
            {
                ob.BuildProgressModels.Sort((a, b) => a.BuildPercentUpperBound.CompareTo(b.BuildPercentUpperBound));
                this.BuildProgressModels = new BuildProgressModel[ob.BuildProgressModels.Count];
                for (int i = 0; i < BuildProgressModels.Length; ++i)
                {
                    var builderModel = ob.BuildProgressModels[i];
                    if (!string.IsNullOrEmpty(builderModel.File))
                    {
                        this.BuildProgressModels[i] = new BuildProgressModel()
                        {
                            BuildRatioUpperBound = builderModel.BuildPercentUpperBound * CriticalIntegrityRatio,
                            File = builderModel.File,
                            RandomOrientation = builderModel.RandomOrientation
                        };
                    }
                }
            }

            if (ob.GeneratedBlocks != null)
            {
                this.GeneratedBlockDefinitions = new MyDefinitionId[ob.GeneratedBlocks.Length];

                for (int i = 0; i < ob.GeneratedBlocks.Length; ++i)
                {
                    var genBlockId = ob.GeneratedBlocks[i];
                    Debug.Assert(!string.IsNullOrEmpty(genBlockId.SubtypeName));
                    Debug.Assert(!string.IsNullOrEmpty(genBlockId.TypeIdString));

                    this.GeneratedBlockDefinitions[i] = genBlockId;
                }
            }

            Skeleton = ob.Skeleton;
            if (Skeleton != null)
            {
                Bones = new Dictionary <Vector3I, Vector3>(ob.Skeleton.Count);
                foreach (var bone in Skeleton)
                {
                    Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, MyDefinitionManager.Static.GetCubeSize(ob.CubeSize));
                }
            }

            IsAirTight = ob.IsAirTight;

            InitMountPoints(ob);
            InitPressurization();

            InitNavigationInfo(ob, ob.NavigationDefinition);

            CheckBuildProgressModels();
            // Components and CriticalComponent will be initialized elsewhere

            PrimarySound = new MySoundPair(ob.PrimarySound);
            ActionSound  = new MySoundPair(ob.ActionSound);
            if (ob.DamagedSound != null)
            {
                DamagedSound = new MySoundPair(ob.DamagedSound);
            }
        }
コード例 #11
0
        private long SpawnInventoryContainer(MyPhysicalItemDefinition bagDefinition)
        {
            MyEntity builder = Character;
            var worldMatrix = Character.WorldMatrix;
            worldMatrix.Translation += worldMatrix.Up + worldMatrix.Forward;

            MyObjectBuilder_EntityBase bagBuilder = new MyObjectBuilder_EntityBase();
            bagBuilder.Name = bagDefinition.DisplayNameText;
            var position =  new MyPositionAndOrientation(worldMatrix);
            bagBuilder.PositionAndOrientation = position;
            bagBuilder.EntityId = MyEntityIdentifier.AllocateId();
            bagBuilder.SubtypeName = bagDefinition.Id.SubtypeName;

            var entity = MyEntities.CreateAndAddFromDefinition(bagBuilder, bagDefinition);

            entity.Physics.ForceActivate();
            entity.Physics.ApplyImpulse(builder.Physics.LinearVelocity, Vector3.Zero);
            
            MySyncCreate.SendEntityCreated(entity.GetObjectBuilder(), bagDefinition.Id);
            
            return entity.EntityId;
        }