public Alloy Normalized() { var output = new Alloy(); foreach (MetalMass mm in metals) { output.AddMetal(mm.Metal, Purity, mm.Amount / totalAmount); } return(output); }
public static Alloy LoadAlloy(Stream reader) { var output = new Alloy(); if (reader.ReadByte() == 0) //The alloy is empty { return(output); } var buffer = new byte[sizeof(float)]; reader.Read(buffer, 0, buffer.Length); float Purity = BitConverter.ToSingle(buffer, 0); int metalCount = reader.ReadByte(); for (int i = 0; i < metalCount; i++) { int id = reader.ReadByte(); reader.Read(buffer, 0, buffer.Length); float amount = BitConverter.ToSingle(buffer, 0); output.AddMetal(id, Purity, amount); } return(output); }