Пример #1
0
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            Definition = definition as MyModelComponentDefinition;
            Debug.Assert(Definition != null, "Passed null definition or wrong type!");
        }
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            var craftDefinition = definition as MyCraftingComponentBasicDefinition;

            System.Diagnostics.Debug.Assert(craftDefinition != null, "Trying to initialize crafting component from wrong definition type?");


            if (craftDefinition != null)
            {
                ActionSound = new MySoundPair(craftDefinition.ActionSound);
                m_craftingSpeedMultiplier = craftDefinition.CraftingSpeedMultiplier;

                foreach (var blueprintClass in craftDefinition.AvailableBlueprintClasses)
                {
                    var classDefinition = MyDefinitionManager.Static.GetBlueprintClass(blueprintClass);
                    System.Diagnostics.Debug.Assert(classDefinition != null, blueprintClass + " blueprint class definition was not found.");
                    if (classDefinition != null)
                    {
                        m_blueprintClasses.Add(classDefinition);
                    }
                }
            }
        }
Пример #3
0
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            var inventoryComponentDefinition = definition as MyInventoryComponentDefinition;
            if (inventoryComponentDefinition != null)
            {
                m_maxVolume = (MyFixedPoint)inventoryComponentDefinition.Volume;
                m_maxMass = (MyFixedPoint)inventoryComponentDefinition.Mass;
                RemoveEntityOnEmpty = inventoryComponentDefinition.RemoveEntityOnEmpty;
                m_multiplierEnabled = inventoryComponentDefinition.MultiplierEnabled;
                m_maxItemCount = inventoryComponentDefinition.MaxItemCount;
            }
        }
 public override void Init(MyComponentDefinitionBase definition)
 {
     base.Init(definition);
 }
Пример #5
0
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            Definition = definition as MyPhysicsBodyComponentDefinition;
            Debug.Assert(Definition != null);
        }
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            MyEntityStatComponentDefinition entityStatDefinition = definition as MyEntityStatComponentDefinition;
            Debug.Assert(entityStatDefinition != null);

            if (entityStatDefinition == null || !entityStatDefinition.Enabled || MySession.Static == null ||
                (!entityStatDefinition.AvailableInSurvival && MySession.Static.SurvivalMode))
            {
                if (Sync.IsServer) // Only init scripts on server
                {
                    m_statActionsRequested = true;
                }
                return;
            }

            foreach (var statId in entityStatDefinition.Stats)
            {
                MyEntityStatDefinition statDefinition = null;
                if (!MyDefinitionManager.Static.TryGetDefinition(statId, out statDefinition))
                    continue;

                if (!statDefinition.Enabled
                    || (!statDefinition.EnabledInCreative && MySession.Static.CreativeMode)
                    || (!statDefinition.AvailableInSurvival && MySession.Static.SurvivalMode))
                    continue;

                var nameHash = MyStringHash.GetOrCompute(statDefinition.Name);
                MyEntityStat existingStat = null;
                if (m_stats.TryGetValue(nameHash, out existingStat) && existingStat.StatDefinition.Id.SubtypeId == statDefinition.Id.SubtypeId)
                    continue;

                var builder = new MyObjectBuilder_EntityStat();
                builder.SubtypeName = statId.SubtypeName;
                builder.MaxValue = 1.0f;
                builder.Value = statDefinition.DefaultValue / statDefinition.MaxValue;
                AddStat(nameHash, builder);
            }

            if (Sync.IsServer)	// Only init scripts on server
            {
                Debug.Assert(m_scripts.Count == 0);
                foreach (var scriptName in entityStatDefinition.Scripts)
                {
                    InitScript(scriptName);
                }
                m_statActionsRequested = true;
            }
        }
        public static bool TryGetComponentDefinition(MyObjectBuilderType type, MyStringHash subtypeName, out MyComponentDefinitionBase componentDefinition)
        {
            componentDefinition = null;

            if (MyDefinitionManager.Static != null)
            {
                MyDefinitionId subtypeDefinition = new MyDefinitionId(type, subtypeName);
                if (MyDefinitionManager.Static.TryGetEntityComponentDefinition(subtypeDefinition, out componentDefinition))
                    return true;

                // Fallback to EntityBase type
                if (subtypeName != MyStringHash.NullOrEmpty)
                {
                    MyDefinitionId subtypeDefinition_Fallback = new MyDefinitionId(typeof(MyObjectBuilder_EntityBase), subtypeName);
                    if (MyDefinitionManager.Static.TryGetEntityComponentDefinition(subtypeDefinition_Fallback, out componentDefinition))
                        return true;
                }

                MyDefinitionId defaultDefinition = new MyDefinitionId(type);
                if (MyDefinitionManager.Static.TryGetEntityComponentDefinition(defaultDefinition, out componentDefinition))
                    return true;
            }

            return false;
        }
Пример #8
0
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            var timerComponentDefinition = definition as MyTimerComponentDefinition;
            Debug.Assert(timerComponentDefinition != null);
            if (timerComponentDefinition != null)
            {
                TimerEnabled = timerComponentDefinition.TimeToRemoveMin > 0;
                m_setTimeMin = timerComponentDefinition.TimeToRemoveMin;
                TimeToEvent = m_setTimeMin;
                RemoveEntityOnTimer = timerComponentDefinition.TimeToRemoveMin > 0;

                if (RemoveEntityOnTimer)
                {
                    EventToTrigger = GetRemoveEntityOnTimerEvent();
                }
            }
        }
        public override void Init(MyComponentDefinitionBase definition)
        {
            base.Init(definition);

            var inventorySpawnDef = definition as MyEntityInventorySpawnComponent_Definition;

            m_containerDefinition = inventorySpawnDef.ContainerDefinition;
        }