Exemplo n.º 1
0
        public override MyObjectBuilder_ComponentBase Serialize(bool copy = false)
        {
            MyObjectBuilder_ComponentBase          base2     = base.Serialize(false);
            MyObjectBuilder_CharacterStatComponent component = base2 as MyObjectBuilder_CharacterStatComponent;

            if (component == null)
            {
                return(base2);
            }
            component.Stats       = null;
            component.ScriptNames = null;
            if ((this.m_stats != null) && (this.m_stats.Count > 0))
            {
                component.Stats = new MyObjectBuilder_EntityStat[this.m_stats.Count];
                int index = 0;
                foreach (KeyValuePair <MyStringHash, MyEntityStat> pair in this.m_stats)
                {
                    index++;
                    component.Stats[index] = pair.Value.GetObjectBuilder();
                }
            }
            if ((this.m_scripts != null) && (this.m_scripts.Count > 0))
            {
                component.ScriptNames = new string[this.m_scripts.Count];
                int index = 0;
                foreach (MyStatLogic logic in this.m_scripts)
                {
                    index++;
                    component.ScriptNames[index] = logic.Name;
                }
            }
            return(component);
        }
Exemplo n.º 2
0
        public override void Deserialize(MyObjectBuilder_ComponentBase objectBuilder)
        {
            MyObjectBuilder_CharacterStatComponent component = objectBuilder as MyObjectBuilder_CharacterStatComponent;

            using (List <MyStatLogic> .Enumerator enumerator = this.m_scripts.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    enumerator.Current.Close();
                }
            }
            this.m_scripts.Clear();
            if (component != null)
            {
                if (component.Stats != null)
                {
                    foreach (MyObjectBuilder_EntityStat stat in component.Stats)
                    {
                        MyEntityStatDefinition definition = null;
                        if ((MyDefinitionManager.Static.TryGetDefinition <MyEntityStatDefinition>(new MyDefinitionId(stat.TypeId, stat.SubtypeId), out definition) && definition.Enabled) && ((definition.EnabledInCreative && MySession.Static.CreativeMode) || (definition.AvailableInSurvival && MySession.Static.SurvivalMode)))
                        {
                            this.AddStat(MyStringHash.GetOrCompute(definition.Name), stat, true);
                        }
                    }
                }
                if ((component.ScriptNames != null) && Sync.IsServer)
                {
                    component.ScriptNames = component.ScriptNames.Distinct <string>().ToArray <string>();
                    foreach (string str in component.ScriptNames)
                    {
                        this.InitScript(str);
                    }
                }
            }
            base.Deserialize(objectBuilder);
        }