private bool ReplaceGasValue(string gasName, float value) { if (Character.StoredGases == null) { Character.StoredGases = new List <MyObjectBuilder_Character.StoredGas>(); } // Find the existing gas value. for (int i = 0; i < Character.StoredGases.Count; i++) { MyObjectBuilder_Character.StoredGas gas = Character.StoredGases[i]; if (gas.Id.SubtypeName == gasName) { if (value != gas.FillLevel) { gas.FillLevel = value; Character.StoredGases[i] = gas; return(true); } } } // If it doesn't exist for old save games, add it in. MyObjectBuilder_Character.StoredGas newGas = new MyObjectBuilder_Character.StoredGas { // This could cause an exception if the gas names are ever changed, even in casing. Id = MyDefinitionManager.Static.GetGasDefinitions().FirstOrDefault(e => e.Id.SubtypeName == gasName).Id, FillLevel = value }; Character.StoredGases.Add(newGas); return(true); }
public virtual void GetObjectBuilder(MyObjectBuilder_Character objectBuilder) { objectBuilder.OxygenLevel = this.SuitOxygenLevel; objectBuilder.EnvironmentOxygenLevel = base.Character.EnvironmentOxygenLevel; objectBuilder.NeedsOxygenFromSuit = this.NeedsOxygenFromSuit; if ((this.m_storedGases != null) && (this.m_storedGases.Length != 0)) { if (objectBuilder.StoredGases == null) { objectBuilder.StoredGases = new List <MyObjectBuilder_Character.StoredGas>(); } foreach (GasData storedGas in this.m_storedGases) { if (objectBuilder.StoredGases.TrueForAll(obGas => obGas.Id != storedGas.Id)) { MyObjectBuilder_Character.StoredGas item = new MyObjectBuilder_Character.StoredGas { Id = (SerializableDefinitionId)storedGas.Id, FillLevel = storedGas.FillLevel }; objectBuilder.StoredGases.Add(item); } } } }