public void InitStats(MyStatsDefinition definition) { if (definition == null) return; foreach(var statId in definition.Stats) { MyEntityStatDefinition statDefinition = null; if (!MyDefinitionManager.Static.TryGetDefinition(statId, out statDefinition)) continue; if (!statDefinition.Enabled || (!statDefinition.EnabledInCreative && MySession.Static.CreativeMode)) continue; var builder = new MyObjectBuilder_EntityStat(); builder.MaxValue = statDefinition.MaxValue; builder.MinValue = statDefinition.MinValue; builder.Value = statDefinition.MaxValue; AddStat(statId.SubtypeId, builder); } Type scriptType; foreach (var scriptName in definition.Scripts) { if (MyScriptManager.Static.StatScripts.TryGetValue(scriptName, out scriptType)) { var script = (MyStatLogic)Activator.CreateInstance(scriptType); script.Init(Entity as MyCharacter, m_stats); m_scripts.Add(script); } } }
public void InitStats(MyStatsDefinition definition) { if (definition == null || !definition.Enabled || (!definition.AvailableInSurvival && MySession.Static.SurvivalMode)) return; foreach (var statId in definition.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(statId.SubtypeId, out existingStat) && existingStat.StatId == nameHash) 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 { // MW: remove all scripts because of the broken saves (Medieval character has multiple scripts (peasant's and player's)) foreach (var script in m_scripts) { script.Close(); } m_scripts.Clear(); foreach (var scriptName in definition.Scripts) { InitScript(scriptName); } } else { RequestStatActions(); // Only request the stat actions from the server } }
public void InitStats(MyStatsDefinition definition) { if (definition == null || !definition.Enabled || (!definition.AvailableInSurvival && MySession.Static.SurvivalMode)) return; foreach (var statId in definition.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(statId.SubtypeId, out existingStat) && existingStat.StatId == nameHash) continue; var builder = new MyObjectBuilder_EntityStat(); builder.SubtypeName = statId.SubtypeName; builder.MaxValue = 1.0f; builder.Value = 1.0f; AddStat(nameHash, builder); } if (Sync.IsServer) // Only init scripts on server { foreach (var scriptName in definition.Scripts) { MyStatLogic script = null; if ((script = m_scripts.Find((otherScript) => { return otherScript.Name == scriptName; })) != null) { script.Close(); m_scripts.Remove(script); // On load we might've had less stats to consider (moving from creative to survival for example) so replace the old script } InitScript(scriptName); } } else { RequestStatActions(); // Only request the stat actions from the server } }