Ejemplo n.º 1
0
        public virtual void Init(MyObjectBuilder_Base objectBuilder)
        {
            var builder = (MyObjectBuilder_EntityStat) objectBuilder;

            MyEntityStatDefinition definition;
            MyDefinitionManager.Static.TryGetDefinition<MyEntityStatDefinition>(new MyDefinitionId(builder.TypeId, builder.SubtypeId), out definition);

            Debug.Assert(definition != null);
            StatDefinition = definition;

            m_maxValue = builder.MaxValue * 100.0f;
            m_minValue = 0.0f;
            m_currentValue = builder.Value * m_maxValue;
            
            m_lastSyncValue = m_currentValue;
            m_statId = MyStringHash.GetOrCompute(definition.Name);

            if (builder.Effects != null)
            {
                foreach (var effectBuilder in builder.Effects)
                {
                    AddEffect(effectBuilder);
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void Init(MyObjectBuilder_Base objectBuilder)
        {
            var builder = (MyObjectBuilder_EntityStat) objectBuilder;

            MyEntityStatDefinition definition;
            MyDefinitionManager.Static.TryGetDefinition<MyEntityStatDefinition>(new MyDefinitionId(builder.TypeId, builder.SubtypeId), out definition);

            Debug.Assert(definition != null);
            StatDefinition = definition;

            System.Diagnostics.Debug.Assert(!float.IsNaN(definition.MaxValue) && !float.IsNaN(definition.MinValue) && !float.IsNaN(definition.DefaultValue), "Invalid values in stat definition!");

            m_maxValue = definition.MaxValue;
            m_minValue = definition.MinValue;
            m_currentValue = builder.Value * m_maxValue;
            m_defaultValue = definition.DefaultValue;
            
            m_lastSyncValue = m_currentValue;
            m_statId = MyStringHash.GetOrCompute(definition.Name);

            m_regenAmountMultiplier = builder.StatRegenAmountMultiplier;
            m_regenAmountMultiplierDuration = builder.StatRegenAmountMultiplierDuration;
            m_regenAmountMultiplierTimeStart = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_regenAmountMultiplierTimeAlive = 0;
            m_regenAmountMultiplierActive = m_regenAmountMultiplierDuration > 0;

            ClearEffects();
            if (builder.Effects != null)
            {
                foreach (var effectBuilder in builder.Effects)
                {
                    AddEffect(effectBuilder);
                }
            }
        }